better-scroll项目中遇到的问题
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项目中遇到的问题的更多相关文章
- sessionStorage在项目中的应用
1. 本地存储 Cookie(局限性):用户可以禁用cookie,最多只能存储4kb,cookie有过期时间的(一般我们设置的时间最长1个月,用户使用杀毒软件也可以清除我们的cookie)LocalS ...
- java使用elasticsearch进行模糊查询-已在项目中实际应用
java使用elasticsearch进行模糊查询 使用环境上篇文章本人已书写过,需要maven坐标,ES连接工具类的请看上一篇文章,以下是内容是笔者在真实项目中运用总结而产生,并写的是主要方法和思路 ...
- vue项目中遇到的一些问题
或访问:https://github.com/littleHiuman/experiences-about-vue 欢迎补充! vuex 状态 vue-cli 命令行 vue vue vue-rou ...
- SSH 项目中 使用websocket 实现网页聊天功能
参考文章 :java使用websocket,并且获取HttpSession,源码分析 http://www.cnblogs.com/zhuxiaojie/p/6238826.html 1.在项 ...
- Vue项目中使用better-scroll
当 better-scroll 遇见 Vue 在我们日常的移动端项目开发中,处理滚动列表是再常见不过的需求了. 以滴滴为例,可以是这样竖向滚动的列表,如图所示: 也可以是横向滚动的导航栏,如图所示 ...
- better-scroll在vue项目中的使用
1.准备工作 在项目中安装better-scroll: npm install --save better-scroll 组件中引入插件 import BScroll from "bette ...
- vue项目中,单页图片过多,使用懒加载
最近做项目,一页图片很多,加载的时候效果很差. 通过学习借鉴其他大神的方法,使用了插件vue-lazyload,使用这个插件,界面更美观了,加载的效果好起来. 安装 npm i vue-lazyloa ...
- VS项目中使用Nuget还原包后编译生产还一直报错?
Nuget官网下载Nuget项目包的命令地址:https://www.nuget.org/packages 今天就遇到一个比较奇葩的问题,折腾了很久终于搞定了: 问题是这样的:我的解决方案原本是好好的 ...
- ABP项目中使用Swagger生成动态WebAPI
本文是根据角落的白板报的<使用ABP实现SwaggerUI,生成动态webapi>一文的学习总结,感谢原文作者角落的白板报. 1 安装Swashbuckle.core 1.1 选择WebA ...
- iOS 之项目中遇到的问题总结
昨天去一家公司面试,面试官问了我在项目开发中遇到过哪些问题,是什么引起的,怎样解决的? 当时由于有点小紧张只说出了一两点,现在就来好好总结一下. 问题: 1.两表联动 所谓的两表联动就是有左右两个表格 ...
随机推荐
- javascript文件加载模式与加载方法
加载方式 形象图像化方法,见 http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html 1. script标签, ...
- Ubuntu安装MongoDB
一.下载安装 首先,更新软件包列表以获取最新版本的存储库列表: sudo apt update 2.接着安装MongoDB包本身: sudo apt install -y mongodb ×加-y是为 ...
- python 的基础 学习 第七天 is id 编码的补充
1,== 两个等号比较的是数值,is比较的是内存地址.print(id())查看的内存地址. 小数据池只存在于数字与字符串中,数字 是 -5^^256,是为了节省空间. 字符串1,如果含有特殊字符 ...
- react-踩坑记录——swiper报错!
已经在html文件中使用过,正确无误:但做成组件后(各种依赖文件引入路径确认无误)报错. 在只引入swiper.css时未报错,引入swiper.js文件后报错,如下: 错误原因,不详. 解决措施,不 ...
- java知识点2
进阶篇 Java底层知识 字节码.class文件格式 CPU缓存,L1,L2,L3和伪共享 尾递归 位运算 用位运算实现加.减.乘.除.取余 设计模式 了解23种设计模式 会使用常用设计模式 单例.策 ...
- 最简单的HashMap底层原理介绍
HashMap 底层原理 1.HashMap底层概述 2.JDK1.7实现方式 3.JDK1.8实现方式 4.关键名词 5.相关问题 1.HashMap底层概述 在JDK1.7中HashMap采用的 ...
- 使用 ffmpeg nginx rtmp 搭建实时流处理平台
环境: ubuntu 16.04 问题引入: 使用 opencv 获取摄像头数据帧, 进行处理之后(如进行 keypoint 识别), 将 opencv 中图像的 Mat类型转化为 ffmpeg 的 ...
- DeprecationWarning: Calling an asynchronous function without callback is deprecated. - how to find where the “function:” is?
I recently updated my node to 7.2.1 and noticed that there is a warning coming: (node:4346) Deprecat ...
- sublime修改侧边栏字体
安装了sublime的material主题后,侧边栏的字体特别小,设置方法如下: 安装插件 用上面的插件打开 Material-Theme.sublime-theme 如下 { "class ...
- 设计模式C++学习笔记之八(Adapter适配器模式)
适配器模式,使用之处比较特殊,不属于常规设计模式,主要用于不同系统之间的处理.是将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工 ...