首页 > 代码库 > swiper bugs if multi swipers exit

swiper bugs if multi swipers exit

swiper 控件当动态添加时候,会导致混乱。
源码没详细看,笔者猜测可能是每次初始化都有一个唯一ID,所以无法捕捉销毁。
 
一.常用失败解决方案:
①destroy()变量
②reInit()方法似乎也不起作用,笔者引用的swiper3.4.2,找不到此方法。
 
二.成功方案(js操作数组):
swiper has bugs if init many times, so we should init it once only.(初始化一次) 
var exist=false;var Idarray=[‘index‘];for (var i = 0; i < Idarray.length; i++) {    if (Idarray[i] == showedId) {        exist = true;        console.log(‘exist already‘);        return;    }}//only init when it doesn‘t exist.if (!exist) {    Idarray.push(showedId);    console.log(Idarray);    new Swiper(‘#‘ + showedId + ‘-swiper‘, {        pagination: ‘.swiper-pagination‘,        paginationType: ‘fraction‘    });}

 

swiper bugs if multi swipers exit