1、html演示代碼:css
1 <div class="swiper-container"> 2 <div class="swiper-wrapper"> 3 <div class="swiper-slide">Slide 1</div> 4 <div class="swiper-slide">Slide 2</div> 5 <div class="swiper-slide">Slide 3</div> 6 </div> 7 <!-- 若是須要分頁器 --> 8 <div class="swiper-pagination"></div> 9 10 <!-- 若是須要導航按鈕 --> 11 <div class="swiper-button-prev"></div> 12 <div class="swiper-button-next"></div> 13 14 <!-- 若是須要滾動條 --> 15 <div class="swiper-scrollbar"></div> 16 </div>
2、2.1 假設設置每組顯示的3個slide,則js配置如:html
1 var mySwiper = new Swiper ('.swiper-container', {
2 direction: 'vertical', // 垂直切換選項
3 loop: true, // 循環模式選項
4 slidesPerView : 3, // 100%寬度狀況下,顯示3個slide,(原理就是設置每一個slide的寬度爲30%)
5 20 })
3、3.1 假如須要自定義每一個slide的寬度(或者在最後一個slide添加其餘操做),則js配置如:app
1 var mySwiper = new Swiper('.swiper-container',{ 2 slidesPerView : 'auto', // 開啓自定義slide寬度,配合下面css樣式設置便可 3 })
3.二、css配置:ide
1 .swiper-container { 2 width: 100%; 3 height: 100%; 4 } 5 .swiper-slide { // 默認設置slide寬度爲屏幕的80% 6 text-align: center; 7 font-size: 18px; 8 background: #fff; 9 width: 80%; 10 } 11 .swiper-slide:nth-child(2n) { // 2n偶數行slide寬度爲屏幕的60% 12 width: 60%; 13 } 14 .swiper-slide:nth-child(3n) { // 3n奇數行slide寬度爲屏幕的40% 15 width: 40%; 16 } 17
3.3 最終效果以下:oop
4、打完收工。spa