Javascript iDangero.us Swiper循环错误与以前的导航
当使用“上一页”导航按钮在循环中向后移动时,幻灯片似乎从最后一页跳到第一页。问题似乎发生在所有平台上 使用导航前进按预期工作,拖动按预期工作 我在Swiper网站上做了一个基于“中心幻灯片+每个视图自动幻灯片”的演示,只添加了导航htmlJavascript iDangero.us Swiper循环错误与以前的导航,javascript,swiper,Javascript,Swiper,当使用“上一页”导航按钮在循环中向后移动时,幻灯片似乎从最后一页跳到第一页。问题似乎发生在所有平台上 使用导航前进按预期工作,拖动按预期工作 我在Swiper网站上做了一个基于“中心幻灯片+每个视图自动幻灯片”的演示,只添加了导航html 选择呢 loop:true, 循环幻灯片:10张, 长度:正确, 导航:{ nextEl:“.swiper按钮下一步”, prevEl:“.swiper按钮prev”, }, 请点击此处: 在我工作的生产站点中,我使用的是固定宽度的幻灯片,这个问题似乎只有
选择呢
loop:true,
循环幻灯片:10张,
长度:正确,
导航:{
nextEl:“.swiper按钮下一步”,
prevEl:“.swiper按钮prev”,
},
请点击此处:
在我工作的生产站点中,我使用的是固定宽度的幻灯片,这个问题似乎只有在添加时才会出现
roundlength:true,
使用演示小提琴中基于百分比的宽度,无论是否使用“RoundLength”选项,都会出现问题。任何指针…循环功能都只复制DOM节点,这意味着为循环复制的幻灯片也没有附加JS代码,只有渲染结果 我花了两天时间试图弄明白这一点,因此通过使用原始Swiper的方法和事件,我得到了一个半无限循环功能: 将以下内容添加到您的swiper配置中
loop: true,
loopedSlides: 1,
on: {
slideChange: function () {
let lastVisibleItem = this.realIndex + this.params.slidesPerView
let slidesLength = this.slides.length - 2
let lastVisibleIndex = this.realIndex + this.params.slidesPerView
// if swiper reaches the end of displayed items, goToNext redirects swiper to the start
if (lastVisibleItem > slidesLength) {
this.slideTo(1)
}
// if swiper wants to go before the first item, then forward swiper to the last item
if (lastVisibleIndex >= this.slides.length) {
this.slideTo((slidesLength - this.params.slidesPerView) + 1)
}
}
}
Swiper现已更新,错误已修复。