swiper來自官網(wǎng)

Swiper使用方法
1.首先加載插件,需要用到的文件有swiper.min.jsswiper.min.css文件。

<!DOCTYPE html>
<html><head> ... 
    <link rel="stylesheet" href="path/to/swiper.min.css">
    <link rel="stylesheet" href="path/to/animate.min.css">
</head>
<body> ... 
    <script src="path/to/swiper.min.js"></script>
    <script src="path/to/swiper.animate.min.js"></script>
</body>
</html>

如果你的頁面加載了jQuery.js或者zepto.js,你可以選擇使用更輕便的swiper.jquery.min.js。

<!DOCTYPE html>
<html>
<head> ... 
  <link rel="stylesheet" href="path/to/swiper.min.css">
</head>
<body> ... 
    <script src="path/to/jquery.js"></script>
    <script src="path/to/swiper.jquery.min.js"></script>
</body></html>

2.HTML內(nèi)容。

<div class="swiper-container"> 
    <div class="swiper-wrapper">
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div> 
        <div class="swiper-slide">Slide 3</div> 
    </div> 
    <!-- 如果需要分頁器 -->
    <div class="swiper-pagination"></div>
    <!-- 如果需要導(dǎo)航按鈕 -->
    <div class="swiper-button-prev"></div> 
    <div class="swiper-button-next"></div>
    <!-- 如果需要滾動(dòng)條 --> 
    <div class="swiper-scrollbar"></div>
</div>
<!--導(dǎo)航等組件可以放在container之外--> 
<div class="swiper-container slider">
      <div class="swiper-wrapper">
           <div class="swiper-slide" >
                <p class="ani"  swiper-animate-effect="zoomInRight"
 swiper-animate-duration="0.5s" swiper-animate-delay="0.3s">Slide 1</p>
<!--在需要運(yùn)動(dòng)的元素上面增加類名  ani   ,
和其他的類似插件相同,Swiper Animate需要指定幾個(gè)參數(shù):
swiper-animate-effect:切換效果,例如 fadeInUp 
swiper-animate-duration:可選,動(dòng)畫持續(xù)時(shí)間(單位秒),例如 0.5s
swiper-animate-delay:可選,動(dòng)畫延遲時(shí)間(單位秒),例如 0.3s-->
           </div>
      </div>
</div>

3.你可能想要給Swiper定義一個(gè)大小,當(dāng)然不要也行。

.swiper-container { width: 600px; height: 300px;} 

4.初始化Swiper:最好是挨著</body>標(biāo)簽

<script> 
var mySwiper = new Swiper ('.swiper-container', { direction: 'vertical', loop: true, 
// 如果需要分頁器
 pagination: '.swiper-pagination', 
// 如果需要前進(jìn)后退按鈕 
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev', 
// 如果需要滾動(dòng)條 scrollbar: '.swiper-scrollbar', }) ;
var slider = new Swiper('.slider',{

             onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
                swiperAnimateCache(swiper); //隱藏動(dòng)畫元素 
                swiperAnimate(swiper); //初始化完成開始動(dòng)畫
              }, 

            onSlideChangeEnd: function(swiper){
                    var i =swiper.activeIndex;
                    mySwiper.slideTo(i,1000);
                     swiperAnimate(swiper); 

                
                }


            })     

</script>
</body>

如果不能寫在HTML內(nèi)容的后面,則需要在頁面加載完成后再初始化。

<script type="text/javascript">
    window.onload = function() { ...}
</script>

或者這樣(Jquery和Zepto)

<script type="text/javascript">
    $(document).ready(function () { ...})
</script>

5.完成。恭喜你,現(xiàn)在你的Swiper應(yīng)該已經(jīng)能正常切換了,如果沒有,你可以參考下這個(gè)測(cè)試包?,F(xiàn)在開始添加各種選項(xiàng)和參數(shù)豐富你的Swiper,開啟華麗移動(dòng)前端創(chuàng)作之旅。
*建議不使用Source Map功能,請(qǐng)把js壓縮文件最后一行//# sourceMappingURL=maps/swiper.min.js.map 刪掉。

研究Swiper API文檔

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在線閱讀 http://interview.poetries.top[http://interview.poetr...
    前端進(jìn)階之旅閱讀 115,566評(píng)論 24 450
  • 框架一 :: Animate.css Animate.css是一個(gè)css動(dòng)畫樣式庫,可以減少我們的開發(fā)時(shí)間.它預(yù)設(shè)...
    西巴擼閱讀 3,150評(píng)論 0 5
  • 深夜總是來得猝不及防。沉在高跟鞋的混沌世界里差點(diǎn)沒出得來。 盡管如此,我還是知道了中國以一比零的比...
    山野_pingtan閱讀 528評(píng)論 4 0
  • 那一年的一幅畫,那一年,我14歲;那一年,在14年前;懵懂無知,性格內(nèi)向,不擅長與人交往。唯一陪伴我的是12色中華...
    沈洛川閱讀 368評(píng)論 0 2
  • 四年前在原公司組織的營銷班中,全脫產(chǎn)一年學(xué)習(xí)營銷知識(shí),念了十多本書,其中一本就是《市場(chǎng)營銷學(xué)》。這本書之所以經(jīng)典,...
    100曉東閱讀 2,286評(píng)論 0 7

友情鏈接更多精彩內(nèi)容