首页 > 其他 > 详细

swiper bugs if multi swipers exit

时间:2017-05-22 11:29:00      阅读:305      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/defoliate/p/6888452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!