时间:2021-07-01 10:21:17 帮助过:29人阅读
<div class="swiper-container swiper-container-h"> <div class="swiper-wrapper"> <div class="swiper-slide">Horizontal Slide 1</div> <div class="swiper-slide"> <div class="swiper-container swiper-container-v"> <div class="swiper-wrapper"> <div class="swiper-slide">Vertical Slide 1</div> <div class="swiper-slide">Vertical Slide 2</div> <div class="swiper-slide">Vertical Slide 3</div> <div class="swiper-slide">Vertical Slide 4</div> <div class="swiper-slide">Vertical Slide 5</div> </div> <div class="swiper-pagination swiper-pagination-v"></div> </div> </div> <div class="swiper-slide">Horizontal Slide 3</div> <div class="swiper-slide">Horizontal Slide 4</div> </div> <!-- Add Pagination --> <div class="swiper-pagination swiper-pagination-h"></div> </div>
我们可以看到,这次在swiper的外部容器当中添加了一个类名,swiper-container-h,这个类名其实我们可以随便取一个,作为一个标记,记录我们这个外部容器为哪一个swiper页面的外部容器,我们在初始化的时候是要绑定它的,然后有几个swiper的页面我们就要初始化几次,并且每一个初始化都要绑定到不同的swiper页面的外部容器上面,不然的话我们的页面样式就会错乱,下面进行初始化。
var swiperH = new Swiper('.swiper-container-h', { pagination: '.swiper-pagination-h', paginationClickable: true, spaceBetween: 50 }); var swiperV = new Swiper('.swiper-container-v', { pagination: '.swiper-pagination-v', paginationClickable: true, direction: 'vertical', spaceBetween: 50 });
这里因为有俩个swiper页面所以分别初始化了俩次,然后要分别设定每个swiper页面的CSS样式,以及每一个swiper页面当中的属性。注意,绑定的外部容器类名一定部能相同,不然一个页面初始化俩次会造成样式错乱。
以上就是 swiper的基础使用(十)的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!