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.两表联动 所谓的两表联动就是有左右两个表格 ...
随机推荐
- 15个新鲜出炉的 Photoshop 文本效果教程
文本效果可能是 Photoshop 图形设计中最常用和最通用的技术之一.最重要的是你可以使用任何效果,风格或纹理来产生有趣的排版,越多人尝试过它并制作了一些精彩的教程.所以这篇文章旨在为您提供全面的 ...
- 判断闰年(Java)
package day01; import java.util.Scanner; public class leap_year { public static void main (String[] ...
- tensorflow---alexnet training (tflearn)
# 输入数据 import input_data mnist = input_data.read_data_sets("/tmp/data/", one_hot=True) imp ...
- Python文件读取常用方法
1. 关于读取文件 f.read() 读取文件中所有内容 f.readline() 读取第一行的内容 f.readlines() 读取文件里面所有内容,把每行的内容放到一个list里面 注:因为文件指 ...
- redis集群学习
转载: http://arganzheng.life/redis-cluster.html Redis3.0版本加入了cluster功能,解决了Redis单点无法横向扩展的问题. 分布式系统要解决的不 ...
- Linux故障:linux中使用ifconfig命令查看网卡信息时显示为eth1,但是在network-scripts中只有ifcfg-eth0的配置文件,并且里面的NAME="eth0"。
linux中使用ifconfig命令查看网卡信息时显示为eth1,但是在network-scripts中只有ifcfg-eth0的配置文件,并且里面的NAME="eth0". ...
- AOP 横行切面编程和 纵向编程 介绍
1 aop:面向切面(方面)编程,扩展功能不修改源代码实现 2 AOP采取横向抽取机制,取代了传统纵向继承体系重复性代码3 aop底层使用动态代理实现(1)第一种情况,有接口情况,使用动态代理创建接口 ...
- j假设程序需要要一个int烈血的刀变量来保存1英里所包含的步数(5280)为该变量编写一条声明语句。
j假设程序需要要一个int烈血的刀变量来保存1英里所包含的步数(5280)为该变量编写一条声明语句. final intFT_PER_MILE =5280
- log4j - 输出格式控制, PatternLayout参数含义以及详细配置
转载自:https://blog.csdn.net/reserved_person/article/details/52849505 做项目被log4j的输出格式化参数搞烦了,索性把API的相关部分大 ...
- Nginx安装及配置详解【转】
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...