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. Devexpress Winform 使用MVVM

    MVVM在WPF里很早就有了,在Winform里Devexpress最近几个大版本才有的事,上一段代码. 现在对话框上添加三个控件simpleButton1,simpleButton2,textEdi ...

  2. [译]Managing Vue.js State with Vuex

    原文 准备 安装 Vuex, 是Vue官方出的package, 它不是Vue内置的.需要另外安装. npm install vuex --save 然后,需要在应用启动文件启用Vuex. main.j ...

  3. 面向对象 ( OO ) 的程序设计——创建对象

    本文地址:http://www.cnblogs.com/veinyin/p/7608000.html  为了避免大量重复代码产生,可采用以下方法创建对象 1 工厂模式 function createP ...

  4. Coursera, Deep Learning 4, Convolutional Neural Networks, week3, Object detection

    学习目标 Understand the challenges of Object Localization, Object Detection and Landmark Finding Underst ...

  5. NoClassDefFoundError与ClassNOtFoundException的区别

    NoClassDefFoundError是一个错误(Error),而ClassNOtFoundException是一个异常,在Java中对于错误和异常的处理是不同的,我们可以从异常中恢复程序但却不应该 ...

  6. python练习题1

    1.使用while循环打印输入 1 2 3 4 5 6 8 9 10 num = 1 while num <= 10: if num == 7: num = num + 1 continue e ...

  7. Liunx/RHEL6.5 Oracle11 安装记录[缺少依赖包的解决方案]

    1.将镜像文件挂,如/mnt # mount -o loop rhel-server-6.1-x86_64-dvd.iso /mnt#这一步其实有很多实现方法,如可以将镜像文件中的Packages文件 ...

  8. eclipse连接手机一直连接不起

    任何环境都搭配没有问题,依然连接不起手机,最后解决办法: 把sdk下tools的文件全部复制一份到platform-tools下即可

  9. 论文笔记:Rich feature hierarchies for accurate object detection and semantic segmentation

    在上计算机视觉这门课的时候,老师曾经留过一个作业:识别一张 A4 纸上的手写数字.按照传统的做法,这种手写体或者验证码识别的项目,都是按照定位+分割+识别的套路.但凡上网搜一下,就能找到一堆识别的教程 ...

  10. 框架中的导航框架 & position定位

    框架中,通过链接将一个页面显示在另一个框架中:   总框架: <frameset cols="15%,*">   <frame src="xx.html ...