欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

swiper自定義分頁(yè)器使用方法詳解

 更新時(shí)間:2020年09月14日 08:24:10   作者:夏爾_  
這篇文章主要為大家詳細(xì)介紹了swiper自定義分頁(yè)器的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了swiper自定義分頁(yè)器使用的具體代碼,供大家參考,具體內(nèi)容如下

解決問(wèn)題:不想使用swiper的自帶的圓鈕式的分頁(yè)器,想使用自定義的分頁(yè)器。

解決方案:利用swiper提供的paginationCustomRender()方法(自定義特殊類型分頁(yè)器,當(dāng)分頁(yè)器類型設(shè)置為自定義時(shí)可用。)
下面的代碼可以直接賦值粘貼到html文件里面然后作為項(xiàng)目在瀏覽器打開(kāi),但是圖片需要你引用自己的本地圖片并設(shè)置好路徑,否則你是看不到輪播圖片的。代碼如下(參考注釋很重要):

<!DOCTYPE html> 
<html> 
 
 <head> 
 <meta charset="UTF-8"> 
 <title>swiper自定義分頁(yè)器用法</title> 
 <link href="swiper-3.4.2.min.css" rel="stylesheet" /> 
 <style> 
 * { 
 padding: 0; 
 margin: 0; 
 } 
 
 .swiper-container { 
 position: relative; 
 width: 100%; 
 height: 100%; 
 } 
 
 .swiper-slide { 
 text-align: center; 
 font-size: 18px; 
 background: #fff; 
 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 { 
 display: block; 
 width: 100%; 
 max-width: 100%; 
 } 
 /*包裹自定義分頁(yè)器的div的位置等CSS樣式*/ 
 .swiper-pagination-custom { 
 bottom: 10px; 
 left: 0; 
 width: 100%; 
 } 
 /*自定義分頁(yè)器的樣式,這個(gè)你自己想要什么樣子自己寫*/ 
 .swiper-pagination-customs { 
 width: 30px; 
 height: 4px; 
 display: inline-block; 
 background: #000; 
 opacity: .3; 
 margin: 0 5px; 
 } 
 /*自定義分頁(yè)器激活時(shí)的樣式表現(xiàn)*/ 
 .swiper-pagination-customs-active { 
 opacity: 1; 
 background-color: #F78E00; 
 } 
 </style> 
 </head> 
 
 <body> 
 <div class="swiper-container"> 
 <div class="swiper-wrapper"> 
 <div class="swiper-slide"> 
  <img src="banner1_.jpg" alt="輪播圖1" /> 
 </div> 
 <div class="swiper-slide"> 
  <img src="banner2_.jpg" alt="輪播圖2" /> 
 </div> 
 </div> 
 <div class="swiper-pagination"></div> 
 </div> 
 </body> 
 <script src="jquery.min.js"></script> 
 <script type="text/javascript" src="swiper.min.js"></script> 
 <script> 
 var mySwiper = new Swiper('.swiper-container', { 
 direction: 'horizontal', 
 loop: true, 
 autoplay: 3000,//自動(dòng)輪播 
 speed: 600, 
 // 如果需要分頁(yè)器 
 pagination: '.swiper-pagination', 
 paginationType: 'custom',//這里分頁(yè)器類型必須設(shè)置為custom,即采用用戶自定義配置 
 //下面方法可以生成我們自定義的分頁(yè)器到頁(yè)面上 
 paginationCustomRender: function(swiper, current, total) { 
 var customPaginationHtml = ""; 
 for(var i = 0; i < total; i++) { 
  //判斷哪個(gè)分頁(yè)器此刻應(yīng)該被激活 
  if(i == (current - 1)) { 
  customPaginationHtml += '<span class="swiper-pagination-customs swiper-pagination-customs-active"></span>'; 
  } else { 
  customPaginationHtml += '<span class="swiper-pagination-customs"></span>'; 
  } 
 } 
 return customPaginationHtml; 
 } 
 }); 
 </script> 
 
</html>

代碼效果圖如下(上傳圖片大小有限制,所以我滑的有點(diǎn)快):

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論