swiper3多个进行display:none切换时,会造成切换后无法自动播放和位移的情况用一下方法就可解决
1、初始化添加observer: true,observerParents: true参数,解决位移或错位的问题
var Swiper = new Swiper(".index", { loop: true, observer:true, observeParents:true, autoplay: 1000, //可选选项,自动滑动 spaceBetween: 20, autoplayDisableOnInteraction: false, //注意此参数,默认为true // 如果需要分页器 pagination: "", paginationClickable: true });
2、在切换后初始化Swiper就解决无法自动播放的问题
$('#anniu').on('click',function () { for(var i in Swiper){ Swiper[i].init(); Swiper[i].stopAutoplay(); Swiper[i].startAutoplay(); } });