1. 程式人生 > >swiper插件的圖片輪播

swiper插件的圖片輪播

pda das leon his div app rip ted support

<div class="row_3">
              <div class="swiper-container">
                  <div class="swiper-wrapper">
                      <div class="swiper-slide">
                          <img src="../img/pd-bg-01.png">
                          <div class="card-img-overlay"
> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <
p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-02.png"> <
div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-03.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-04.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-05.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-055.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-011.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-022.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-033.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-044.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-033.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> <div class="swiper-slide"> <img src="../img/pd-bg-044.png"> <div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> </div> </div> </div> &lt;!&ndash; Add Pagination &ndash;&gt; <div class="swiper-pagination"></div> &lt;!&ndash; Add Arrows &ndash;&gt; <div class="swiper-button-next"></div> <div class="swiper-button-prev"></div> </div> </div>

在body最後添加如下js

<script>
          var swiper = new Swiper(.swiper-container, {
              slidesPerView: 3,
              spaceBetween: 30,
              slidesPerGroup: 3,
              loop: true,
              loopFillGroupWithBlank: true,
              autoplay: true,
              pagination: {
                  el: .swiper-pagination,
                  clickable: true
              },
              navigation: {
                  nextEl: .swiper-button-next,
                  prevEl: .swiper-button-prev,
              },
              // 自動切換
              autoplay: {
                  // 切換時間
                  delay: 3000,
                  // 是否無限播放
                  stopOnLastSlide: false,
                  // 是否受幹擾
                  disableOnInteraction: true,
              }
          });
      </script>

頁面引入這兩個文件:

技術分享圖片

效果如圖:

技術分享圖片技術分享圖片

swiper插件的圖片輪播