2018年6月13日
引用
"better-scroll":
"^1.12.0",
现象:
- 可以轮播,但不能循环(不能从第一张往前翻,不能从最后一张往后翻)
- 按教程里给slider-group增加了2个slider的宽度,但他们出现在轮播图片的末尾(2个空白)
- 第一张图没有对应dot,第二张图对应第一个dot,以此类推
经过网友分享,我又重新整理了下面的问题,部分引用了网友答案
后经网友分享,发现0.1.15中可以正常运行,原来是better-scoll版本的问题,在新版本中,轮播图的bs对象需要这么配置(snap写在一个对象中):
- this.slider = new BScroll(this.$refs.slider, {
- scrollX: true,
- scrollY: false,
- momentum: false, // 惯性
- snap: {
- loop: this.loop, // 循环
- threshold: 0.3,
- speed: 400 // 轮播间隔
- },
- click: true
- })
- dot与图片不对应:
- // bs对象配置方法中(配置后):
- this.slider.on('scrollEnd', () => {
- let pageIndex = this.slider.getCurrentPage().pageX
- // 老版本有,新版去掉:
- // if (this.loop) {
- // pageIndex -= 1
- // }
- this.currentPageIndex = pageIndex
- if (this.autoPlay) {
- clearTimeout(this.timer)
- this._play()
- }
- })
- _play() {
let pageIndex = this.currentPageIndex + 1 - //老版本有,新版删掉
if (this.loop) {
pageIndex += 1
}
this.timer = setTimeout(() => {
//this.slider.goToPage(pageIndex, 0, 400)