码迷,mamicode.com
首页 > 其他好文 > 详细

页面多个 swiper 互补冲突

时间:2018-08-24 02:14:33      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:rect   container   nbsp   str   each   code   var   内容   children   

 

方法一:精简版

$(".swiper-container").each(function(){
    $(this).swiper({
        loop: true,
        initialSlide :0,
        pagination:$(‘.swiper-pagination‘,this),
        nextButton: $(‘.arrow-right‘,this),
        prevButton:$(‘.arrow-left‘,this)
    });
});

 

方法二:

$("ul>li").each(function(){
    var thisClass = $(this).attr("class");
    $(this).children(".swiper-container").swiper({
        loop: true,
        initialSlide :0,
        pagination: ‘.‘+thisClass + " .swiper-pagination",
        nextButton: ‘.‘+thisClass + " .arrow-right",
        prevButton: ‘.‘+thisClass + " .arrow-left"
    });
});

 

 

 

 

<div class="swiper-container banner">
        <div class="swiper-wrapper">
            <div class="swiper-slide" ></div>
            <div class="swiper-slide" ></div>
            <div class="swiper-slide" ></div>
        </div>
        <div class="swiper-pagination banner"></div>
    </div>
    <div class="swiper-container banner1 "> 
        <div class="swiper-wrapper">
            <div class="swiper-slide" ></div>
            <div class="swiper-slide" ></div>
            <div class="swiper-slide" ></div>
        </div>
        <div class="swiper-pagination banner1"></div>
    </div>

 

swiper使用

var swiper1 = new Swiper(‘.banner, {
    pagination: ‘.banner‘,
    direction: ‘vertical‘,
    slidesPerView: 1,
    paginationClickable: true,
    spaceBetween: 0,
    mousewheelControl: true
})



var swiper2 = new Swiper(‘.banner1, {
    pagination: ‘.banner1‘,
    direction: ‘vertical‘,
    slidesPerView: 1,
    paginationClickable: true,
    spaceBetween: 0,
    mousewheelControl: true
  })

 

 

 

 

 

 

swiper内容变化,会重新初始化

observer: true, //修改swiper自己或子元素时,自动初始化swiper 
observeParents: true, //修改swiper的父元素时,自动初始化swiper

 

页面多个 swiper 互补冲突

标签:rect   container   nbsp   str   each   code   var   内容   children   

原文地址:https://www.cnblogs.com/congxueda/p/9527350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!