1. 程式人生 > >使用Swiper實現無線滾動效果

使用Swiper實現無線滾動效果

在HTML body加入以下內容:

<div class="m-detail-show">
 <!-- Swiper -->
 <div class="swiper-container">
 <div class="swiper-wrapper">
 <div class="swiper-slide"><img src="../../img/game/banner.png"></div>
 <div class="swiper-slide"><img src="../../img/game/banner.png"
>
</div> <div class="swiper-slide"><img src="../../img/game/banner.png"></div> <div class="swiper-slide"><img src="../../img/game/default_img_banner.png"></div> <div class="swiper-slide"><img src="../../img/game/default_img_banner.png"></div> <div class
="swiper-slide">
<img src="../../img/game/default_img_banner.png"></div> <div class="swiper-slide"><img src="../../img/game/default_img_banner.png"></div> <div class="swiper-slide"><img src="../../img/game/default_img_banner.png"></div> <div class="swiper-slide"
>
<img src="../../img/game/default_img_banner.png"></div> <div class="swiper-slide"><img src="../../img/game/default_img_banner.png"></div> </div> <!-- Add Pagination --> <div class="swiper-pagination"></div> </div> </div> <!-- Swiper JS --> <script src="../../js/lib/swiper.min.js"></script> <!-- Initialize Swiper --> <script> var swiper = new Swiper('.swiper-container', { pagination: '.swiper-pagination', paginationClickable:true, /*無限輪播*/ autoplayDisableOnInteraction: false, autoplay : 5000 }); </script>
  • m-detail-show:父容器盒子(自己寫的,非必須)
  • swiper-container // Slider main container
  • swiper-wrapper //Additional required wrapper
  • swiper-slide //滑動的子元素
  • swiper-pagination //下方點

css.css:

.m-detail-show{
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 200px;
    border: 0.5px solid #d3d3d3;
}

.swiper-container {
    width: 100%;
    height: 100%;
}

.swiper-wrapper{
    width: 100%;
}


.swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;
    /* Center slide text vertically */
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
}

.swiper-slide>img{
    width: 100%;
    height: 100%;
}

無圖片效果:
這裡寫圖片描述