1、在项目中发现个问题,用better-scroll实现的轮播图和页面滚动条俩个效果一起出现的时候,当鼠标或手指放在轮播图位置的时候,上下滚动的时候,页面滚动条不动

发现最新的版本就会出这个问题,就是官网的例子中也一样,还有cube-ui中的轮播图

https://ustbhuangyi.github.io/better-scroll/#/examples/slide/en

解决办法是:

第一种:轮播图用其他的,不要用better-sacroll,比如可以使用vant里面的轮播图效果https://youzan.github.io/vant/#/zh-CN/swipe。页面滚动效果用better-sacroll的

这有个问题:如果我们的轮播图可以点击跳转,那么在滑动的时候,会触发跳转效果。这时我们就需要做处理,比如给跳转加一个时间判断(感觉这样挺麻烦的)

第二种:不要用新版本的better-scroll,可以使用0.4.0版本的

第三种: 也是现阶段我认为最好的

在于scrollX平级的地方,不要stopPropagation这个属性,如果还不行,就加一个eventPassthrough: 'vertical'

示例代码:

<template>
<div class="slider" ref="slide">
<div class="slider-group" ref="slideGroup">
<slot>
</slot>
</div>
<div v-if="showDot" class="dots" :class="{dots_center : (dots_position === 0),dots_left : (dots_position === 1),dots_right : (dots_position === 2)}">
<span class="dot" :class="{active: currentPageIndex === index }" v-for="(item, index) in dots" :key="index"></span>
</div>
</div>
</template> <script type="text/ecmascript-6">
import {addClass} from 'common/js/dom.js'
import BScroll from 'better-scroll'
import {mapMutations} from 'vuex' export default {
name: 'slider',
props: {
autoPlay: { // 是否开启自动滚动
type: Boolean,
default: true
},
loop: { // 是否开启循环滚动
type: Boolean,
default: true
},
interval: { // 滚动间隔时间
type: Number,
default:
},
showDot: {
type: Boolean,
default: true
},
click: {
type: Boolean,
default: true
},
threshold: {
type: Number,
default: 0.3
},
speed: {
type: Number,
default:
},
dots_position: { // 焦点的位置 0 中间 1 左边 2 右边
type: Number,
default:
},
showItemIndex: {
type: Number,
defalut:
}
},
data() {
return {
dots: [],
currentPageIndex:
}
},
mounted() {
this.update()
window.addEventListener('resize', () => {
if (!this.slide || !this.slide.enabled) {
return
}
clearTimeout(this.resizeTimer)
this.resizeTimer = setTimeout(() => {
if (this.slide.isInTransition) {
this._onScrollEnd()
} else {
if (this.autoPlay) {
this._play()
}
}
this.refresh()
}, )
})
},
activated() {
if (!this.slide) {
return
}
this.slide.enable()
let pageIndex = this.slide.getCurrentPage().pageX
this.slide.goToPage(pageIndex, , )
this.currentPageIndex = pageIndex
if (this.autoPlay) {
this._play()
}
},
deactivated() {
this.slide.disable()
clearTimeout(this.timer)
},
beforeDestroy() {
this.slide.disable()
clearTimeout(this.timer)
},
methods: {
update() {
if (this.slide) {
this.slide.destroy()
}
this.$nextTick(() => {
this.init()
})
},
refresh() {
this._setSlideWidth(true)
this.slide.refresh()
},
prev() {
this.slide.prev()
},
next() {
this.slide.next()
},
init() {
clearTimeout(this.timer)
this.currentPageIndex =
this._setSlideWidth()
if (this.showDot) {
this._initDots()
}
this._initSlide() if (this.autoPlay) {
this._play()
}
},
_setSlideWidth(isResize) {
this.children = this.$refs.slideGroup.children let width =
let slideWidth = this.$refs.slide.clientWidth
for (let i = ; i < this.children.length; i++) {
let child = this.children[i]
addClass(child, 'slider-item') child.style.width = slideWidth + 'px'
width += slideWidth
}
if (this.loop && !isResize) {
width += * slideWidth
}
this.$refs.slideGroup.style.width = width + 'px'
},
_initSlide() {
this.slide = new BScroll(this.$refs.slide, {
scrollX: true,
scrollY: false,
eventPassthrough: 'vertical',
momentum: false,
snap: {
loop: this.loop,
threshold: this.threshold,
speed: this.speed
},
bounce: false,
click: this.click,
freeScroll: true
}) this.slide.on('scrollEnd', this._onScrollEnd) this.slide.on('touchEnd', () => {
if (this.autoPlay) {
this._play()
}
}) this.slide.on('beforeScrollStart', () => {
if (this.autoPlay) {
clearTimeout(this.timer)
}
})
},
_onScrollEnd() {
let pageIndex = this.slide.getCurrentPage().pageX
this.currentPageIndex = pageIndex
if (this.autoPlay) {
this._play()
} else {
// 触发回调,将当前index值作为参数返回到store中
this.saveSIndex(this.currentPageIndex + )
}
},
...mapMutations({
saveSIndex: 'SET_SLIDERINDEX'
}),
_initDots() {
this.dots = new Array(this.children.length)
},
_play() {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.slide.next()
}, this.interval)
}
},
watch: {
loop() {
this.update()
},
autoPlay() {
this.update()
},
speed() {
this.update()
},
threshold() {
this.update()
},
showItemIndex (index) {
this.slide.goToPage(index, , )
}
}
}
</script> <style lang="less" rel="stylesheet/less" type="text/less">
@import "../../common/less/variable"; .slider{
min-height: 1px;
}
.slider-group{
position: relative;
overflow: hidden;
white-space: nowrap;
}
.slider-item{
float: left;
box-sizing: border-box;
overflow: hidden;
text-align: center;
}
.slider-item a{
display: block;
width: %;
overflow: hidden;
text-decoration: none;
}
.slider-item img{
display: block;
width: %;
}
.dots{
position: absolute;
bottom: 30px;
transform: translateZ(1px);
font-size: ;
}
.dots_center{
left: ;
right: ;
}
.dots_left{
left: 30px;
}
.dots_right{
right: 30px;
}
.dot{
display: inline-block;
margin: 8px;
width: 10px;
height: 10px;
border: 2px solid #f8fafc;
border-radius: %;
background: rgba(, , , 0.5);
}
.dot.active{
background: #398ed1;
}
</style>

better-scroll项目中遇到的问题的更多相关文章

  1. sessionStorage在项目中的应用

    1. 本地存储 Cookie(局限性):用户可以禁用cookie,最多只能存储4kb,cookie有过期时间的(一般我们设置的时间最长1个月,用户使用杀毒软件也可以清除我们的cookie)LocalS ...

  2. java使用elasticsearch进行模糊查询-已在项目中实际应用

    java使用elasticsearch进行模糊查询 使用环境上篇文章本人已书写过,需要maven坐标,ES连接工具类的请看上一篇文章,以下是内容是笔者在真实项目中运用总结而产生,并写的是主要方法和思路 ...

  3. vue项目中遇到的一些问题

    或访问:https://github.com/littleHiuman/experiences-about-vue  欢迎补充! vuex 状态 vue-cli 命令行 vue vue vue-rou ...

  4. SSH 项目中 使用websocket 实现网页聊天功能

    参考文章  :java使用websocket,并且获取HttpSession,源码分析    http://www.cnblogs.com/zhuxiaojie/p/6238826.html 1.在项 ...

  5. Vue项目中使用better-scroll

    当 better-scroll 遇见 Vue   在我们日常的移动端项目开发中,处理滚动列表是再常见不过的需求了. 以滴滴为例,可以是这样竖向滚动的列表,如图所示: 也可以是横向滚动的导航栏,如图所示 ...

  6. better-scroll在vue项目中的使用

    1.准备工作 在项目中安装better-scroll: npm install --save better-scroll 组件中引入插件 import BScroll from "bette ...

  7. vue项目中,单页图片过多,使用懒加载

    最近做项目,一页图片很多,加载的时候效果很差. 通过学习借鉴其他大神的方法,使用了插件vue-lazyload,使用这个插件,界面更美观了,加载的效果好起来. 安装 npm i vue-lazyloa ...

  8. VS项目中使用Nuget还原包后编译生产还一直报错?

    Nuget官网下载Nuget项目包的命令地址:https://www.nuget.org/packages 今天就遇到一个比较奇葩的问题,折腾了很久终于搞定了: 问题是这样的:我的解决方案原本是好好的 ...

  9. ABP项目中使用Swagger生成动态WebAPI

    本文是根据角落的白板报的<使用ABP实现SwaggerUI,生成动态webapi>一文的学习总结,感谢原文作者角落的白板报. 1 安装Swashbuckle.core 1.1 选择WebA ...

  10. iOS 之项目中遇到的问题总结

    昨天去一家公司面试,面试官问了我在项目开发中遇到过哪些问题,是什么引起的,怎样解决的? 当时由于有点小紧张只说出了一两点,现在就来好好总结一下. 问题: 1.两表联动 所谓的两表联动就是有左右两个表格 ...

随机推荐

  1. ubuntu没有/usr/include/sys目录

    实际上不是没有sys目录,只是系统给换路径了 32位系统:/usr/incude/i386-linux-gnu/sys 64位系统:/usr/include/x86_64-linux-gnu/sys/ ...

  2. ubuntu普通用户使用wireshark的权限问题

    解决办法如下: 一.添加wireshark用户组 sudo groupadd wireshark 二.将dumpcap更改为wireshark用户组 sudo chgrp wireshark /usr ...

  3. 另一种的SQL注入和DNS结合的技巧

    这个技巧有些另类,当时某业界大佬提点了一下.当时真的真的没有理解到那种程度,现在可能也是没有理解到,但是我会努力. 本文章是理解于:http://netsecurity.51cto.com/art/2 ...

  4. form表单post提交的数据格式

    1.浏览器行为:Form表单提交 action:url 地址,服务器接收表单数据的地址 method:提交服务器的http方法,一般为post和get name:最好好吃name属性的唯一性 enct ...

  5. 【tmos】字段create_time如何动态的生成

    1.数据库create_time字段默认值设置为CURRENT_TIMESTAMP,实体类中不映射createTime字段,在用jpa的save()方法时,会自动生成,如果你传了null值到数据库,是 ...

  6. 在IDEA中新建Spring Boot项目

    新建项目 选择项目构建方式 选择项目依赖 新建项目成功后(Maven构建方式)

  7. 【Linux】LD_PRELOAD用法

    转载https://blog.csdn.net/iEearth/article/details/49952047 还有一篇博客也可以看看https://blog.csdn.net/xp5xp6/art ...

  8. Redis 深度历险

    学习资料 https://juejin.im/book/5afc2e5f6fb9a07a9b362527 包括下面几方面的内容 基础 应用 原理 集群 拓展 源码 to be done

  9. 《jQuery精品教程视频》视频目录

    \day01\03-视频\02-使用js的缺点.avi; \day01\03-视频\03-jQuery初体验.avi; \day01\03-视频\04-什么是jQuery.avi; \day01\03 ...

  10. 【转载】论文笔记系列-Tree-CNN: A Deep Convolutional Neural Network for Lifelong Learning

    一. 引出主题¶ 深度学习领域一直存在一个比较严重的问题——“灾难性遗忘”,即一旦使用新的数据集去训练已有的模型,该模型将会失去对原数据集识别的能力.为解决这一问题,本文提出了树卷积神经网络,通过先将 ...