遍历实例化swiper


var list = $('.p04-s2 li');
list.each(function (index) {
new Swiper ($(this).find('.swiper-container'), {
spaceBetween: 10,
slidesPerView : 3,
watchOverflow: true,
centeredSlides : true,
loop: true,
breakpoints: {
1500: {
slidesPerView: 2
},
1200: {
slidesPerView: 1
}
},
pagination: {
el: $(this).find('.swiper-pagination'),
clickable :true
},
navigation: {
prevEl: $(this).find('.prev-btn'),
nextEl: $(this).find('.next-btn'),
}
});
});

如果是tab下遍历swiper

 
        function initSwiper($element) {
            new Swiper ($element.find('.swiper-container'), {
                spaceBetween: 20,
                slidesPerView : s1PerNum,
                watchOverflow: true,
                loopedSlides: 5,
                loop: isLoop($element.find('.swiper-slide'), s1PerNum),
                breakpoints: { 
                    1366: {
                        slidesPerView: 3
                    },
                    960: {
                        slidesPerView: 2
                    },
                    540: {
                        slidesPerView: 1
                    }
                },
                navigation: {
                    prevEl: $element.find('.prev'),
                    nextEl: $element.find('.next')
                }
            }); 
        }
 
        $('.tab li').click(function() {
            $('.tab li').removeClass('current');
            $(this).addClass('current');
            var clickIndex = $(this).index();
            $currentLI = $('.text-slider > li').removeClass('active').eq(clickIndex).addClass('active');
            if (!$currentLI.data('initState')) {
                initSwiper($currentLI);
                $currentLI.data('initState', true);
            }
        }).eq(0).trigger('click'); 

 

posted on 2019-12-11 10:36  巧丽  阅读(996)  评论(0编辑  收藏  举报

导航