H5制作顯示輪播圖的方法Swiper


1、需要引入Swiper插件

 <!-- swiper插件 -->
 <link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
 <link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">
 <script src="https://unpkg.com/swiper/js/swiper.js"> </script>
 <script src="https://unpkg.com/swiper/js/swiper.min.js"> </script>

 

2、輪播圖的html結構

 <div class="swiper-container">
      <div class="swiper-wrapper">
              <div class="swiper-slide" v-for="(item,index) in swiperImgList">
                      <img :src="item" alt="">
              </div>
      </div>
      <div class="swiper-pagination"></div> 
  </div>
.swiper-pagination-bullet {  // 小圓點未激活的css
    background: #fff !important;
    opacity: 0.5 !important;
}

.swiper-pagination-bullet-active {  //小圓點激活的樣式
    background: #fff !important;
    opacity: 1 !important;
}

3、js代碼如下

initSwiper() {
      var mySwiper = new Swiper('.swiper-container', {
            speed: 1000,
            autoplay: {
                delay: 3000,
                disableOnInteraction: false   //手動滑動后,繼續自動滑動
            },
            pagination: {
              el: '.swiper-pagination',
            }, 
            loop: true
   })
},

 

如上。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM