我可以使用来获取当前幻灯片的索引this.realIndex
,如文档中所示,但this.previousIndex
无法产生先前活动幻灯片的realIndex。相反,它提供的等效于activeIndex
,当滑块循环时会反映出来。如何获得realIndex
以前活动的幻灯片的图片?这是Swiper中的错误吗?这可能需要进入本地存储吗?
这是我的笔,将幻灯片索引记录到控制台。注意previousIndex
没有什么用:https : //codepen.io/thenomadicmann/pen/GRRPeWG?editors=1111
@neevany离得很近,让我走上了正轨。但是,对于希望使用slideChange事件访问循环的Swiper中的previousIndex的任何人,您不仅需要纠正他描述的-1索引问题,还需要纠正在swwiper循环时发生的double slideChange事件。代码如下:
// Have to use previousIndex in this fashion due to a bug in Swiper.js as of 11/21/19
let previousIndex = this.previousIndex - 1;
if ( previousIndex == -1 ) {
previousIndex = 0;
} else if ( previousIndex == document.querySelectorAll( '.swiper-slide' ).length ) { // When swiper loops, slideChange gets fired twice and messes up animations. This prevents it from doing so.
return;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句