站長資訊網(wǎng)
        最全最豐富的資訊網(wǎng)站

        一個(gè)簡單實(shí)用的js插件–Swiper

        Swiper(Swiper master)是目前應(yīng)用較廣泛的移動(dòng)端網(wǎng)頁觸摸內(nèi)容滑動(dòng)js插件,可以用來做輪播和滑動(dòng).

        • 初始化

          <!DOCTYPE html><html>    <head>  <meta charset="UTF-8">  <title></title>  <link rel="stylesheet" type="text/css" href="swiper.css?1.1.11"/>  <style>  .swiper-container {  width: 600px;  height: 300px;  }             .swiper-slide{  font-size: 50px          }  .swiper-slide:nth-of-type(1){  background-color: cornflowerblue;  }  .swiper-slide:nth-of-type(2){  background-color: coral;  }  .swiper-slide:nth-of-type(3){  background-color: yellowgreen;  }  </style>    </head>    <body>  <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之外-->  <script src="swiper.js?1.1.11"></script>  <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',            })</script>    </body></html>
        • 基本配置

          var mySwiper = new Swiper ('.swiper-container', {                     // 滑動(dòng)方向                    // horizontal水平                    // vertical垂直                direction: 'horizontal',                // 初始化時(shí)候slide的索引(從0開始)                initialSlide: 1,                                // 手指松開至slide貼合的時(shí)間                speed:3000,                                // 設(shè)置自動(dòng)播放的事件間隔                autoplay: 2000,                // 可顯示數(shù)量                slidesPerView:2,                                // 滑塊居中                centeredSlides:true,            })
        • 觸摸設(shè)置

            var mySwiper = new Swiper ('.swiper-container', {                direction: 'horizontal',                  // 觸摸距離與slide滑動(dòng)距離的比率                 touchRatio:0.1,                  // 無法滑動(dòng)                onlyExternal:true,                  // 滑塊跟隨手指進(jìn)行移動(dòng)                followFinger:false,                  // 定義longSwipesMs                longSwipesMs:1000,                  longSwipes:false,                  shortSwipes:false,                  longSwipesRatio:0.5,                  touchAngle:10,            })  禁止切換和前進(jìn)后退 <body> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide stop">Slide 1</div> <!--<div class="swiper-slide swiper-no-swiping">Slide 2</div>--> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> </div> </div> <button class="prev">prev</button> <button class="next">next</button> <script src="swiper.js?1.1.11"></script> <script>                   var mySwiper = new Swiper ('.swiper-container', {               direction: 'horizontal',               noSwiping:true,               noSwipingClass : "stop",               nextButton : ".next",               prevButton : ".prev",           })       </script>分頁器      <style>  .swiper-container {  width: 600px;  height: 300px;  }             .swiper-slide{  font-size: 50px          }  .swiper-slide:nth-of-type(1){  background-color: cornflowerblue;  }  .swiper-slide:nth-of-type(2){  background-color: coral;  }  .swiper-slide:nth-of-type(3){  background-color: yellowgreen;  }  .swiper-pagination-bullet{  width: 20px;  height: 20px;  }  .swiper-pagination-bullet-active{  background-color: yellow;  }  </style>    </head>    <body>  <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>  </div>  <script src="swiper.js?1.1.11"></script>  <script>                    var mySwiper = new Swiper ('.swiper-container', {                direction: 'horizontal',                                pagination : ".swiper-pagination",                                paginationType : "bullets",                paginationType : "fraction",                paginationType : "progress",                                paginationClickable : true,                paginationHide : true,                paginationElement : "i",                paginationBulletRender : function( swiper,index,classname ){                  return "<span class='"+ classname +"'>"+ (index+1) +"</span>"  }            })</script>    </body>切換效果  <script>                    var mySwiper = new Swiper ('.swiper-container', {                direction: 'horizontal',                  effect : "slide",                effect : "fade",                effect : "cube",                effect : "coverflow",                effect : "flip",            })</script>進(jìn)程<body>  <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>  <button id="btn">按鈕</button>  <script src="swiper.js?1.1.11"></script>  <script>                    var mySwiper = new Swiper ('.swiper-container', {                direction: 'horizontal',              })              btn.onclick = function(){                alert( mySwiper.progress );                alert( mySwiper.slides[0].progress );                console.log( mySwiper.slides[0].progress,mySwiper.slides[1].progress,mySwiper.slides[2].progress );            }              setInterval(function(){                console.log( mySwiper.slides[0].progress,mySwiper.slides[1].progress,mySwiper.slides[2].progress );            },20)</script>    </body>
        • 常用屬性和回調(diào)

          <body>  <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>  <button id="btn">按鈕</button>  <script src="swiper.js?1.1.11"></script>  <script>                    var mySwiper = new Swiper ('.swiper-container', {                direction: 'horizontal',                  speed : 2000,                  onSlideChangeStart : function(){                    console.log( "開始滑動(dòng)" );                },                onSlideChangeEnd : function(){                    console.log( "滑動(dòng)結(jié)束" );                }            })              console.log( mySwiper.width );            console.log( mySwiper.height );              btn.onclick = function(){                console.log( mySwiper.translate );                console.log( mySwiper.activeIndex );                console.log( mySwiper.previousIndex );            }        </script>    </body>

        贊(0)
        分享到: 更多 (0)
        網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)
        主站蜘蛛池模板: 亚洲AV无码成人精品区大在线| 在线精品自拍无码| 婷婷成人国产精品| 亚洲国产精品第一区二区| 亚洲日韩国产AV无码无码精品 | 日本精品一区二区三区在线视频| 国产一精品一AV一免费| 亚洲精品WWW久久久久久| 国产精品亚洲专区无码WEB| 国产91精品在线观看| 人妻熟妇乱又伦精品视频| 久久夜色精品国产亚洲av| 日本精品不卡视频| 97在线精品视频| 久久精品中文字幕无码绿巨人| 亚洲欧美国产∧v精品综合网| 国产午夜精品理论片 | 91在线视频精品| 精品人伦一区二区三区潘金莲| 在线观看亚洲精品福利片 | 久久精品国产亚洲77777| 亚洲国产精品狼友中文久久久| 精品国产青草久久久久福利| 99热这里只有精品6国产免费| 久久青草国产精品一区| 国产精品视频网| 国产亚洲精品xxx| 国产精品三级在线| 国产精品美女久久久久网| 97久久久久人妻精品专区| 久久99精品久久久久子伦| 人妻精品久久久久中文字幕69 | 国产精品亚洲产品一区二区三区| 四虎影视国产精品永久在线 | 亚洲精品无码永久中文字幕| 亚洲爆乳无码精品AAA片蜜桃| 日韩精品无码人妻一区二区三区| 无码乱码观看精品久久| 亚洲精品高清一二区久久| 亚洲精品国产美女久久久| 亚洲国产精品无码专区在线观看|