最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

swiper自定義分頁器的樣式

 更新時間:2020年09月14日 08:27:40   作者:weixin_45803990  
這篇文章主要為大家詳細(xì)介紹了swiper自定義分頁器的樣式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

js主要代碼

pagination: {
     // 自定義分頁器的類名----必填項
    el: '.custom-pagination',

     // 是否可點擊----必填項
     clickable: true,

     // 分頁的類型是自定義的----必填項
    type: 'custom',

          // 自定義特殊類型分頁器,當(dāng)分頁器類型設(shè)置為自定義時可用。
          renderCustom: function (swiper, current, total) {
           
            console.log(current);//1 2 3 4
          }
},

一、el

分頁器容器的css選擇器或HTML標(biāo)簽。分頁器等組件可以置于container之外,不同Swiper的組件應(yīng)該有所區(qū)分,如#pagination1,#pagination2。

二、分頁器樣式類型 可選

‘bullets' 圓點(默認(rèn))
‘fraction' 分式
‘progressbar' 進度條
‘custom' 自定義

三、renderCustom()

自定義特殊類型分頁器,當(dāng)分頁器類型設(shè)置為自定義時可用。

四、slideToLoop()

在Loop模式下Swiper切換到指定slide。切換到的是slide索引是realIndex

源碼

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <!-- 1、CDN引入文件 -->
  <link rel="stylesheet" >
  <script src="https://unpkg.com/swiper/swiper-bundle.js"> </script>
  <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.2.1.min.js"></script>

  <!--2、文件自己引入 -->
  <!-- <script src="swiper.min.js"></script>
  <link rel="stylesheet" href="swiper.min.css" rel="external nofollow" >
  <script src="jquery.js"></script> -->
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul {
      list-style: none;
      text-align: center;
      overflow: hidden;
    }

    a {
      text-decoration: none;
      color: #000;
    }

    .swiper-content {
      width: 80%;
      overflow: hidden;
      margin: 0 auto;
    }

    .swiper-content .title {
      height: 100px;
      display: flex;
      align-items: center;
      justify-content: space-around;
    }

    .swiper-content .nav-item {
      float: left;
      display: block;
      margin-right: 30px;
      width: 50px;
      height: 30px;
      line-height: 30px;
    }

    /* 點擊的激活樣式 */
    .swiper-content .nav-item.active {
      background-color: #378ee6;
    }

    /* 輪播圖的樣式 */
    .swiper-content .swiper-container {
      height: 300px;
      background-color: pink;
    }

  </style>
</head>

<body>
  <div class="swiper-content">

    <!-- 自定義導(dǎo)航 -->
    <div class="title">
      <!-- 給ul 添加自定義分頁器類名 custom-pagination -->
      <ul class="nav custom-pagination">
        <li class="nav-item active">
          <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a>
        </li>
        <li class="nav-item">
          <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >網(wǎng)站</a>
        </li>
        <li class="nav-item">
          <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >關(guān)于</a>
        </li>
        <li class="nav-item">
          <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >聯(lián)系</a>
        </li>
      </ul>
    </div>

    <!-- 輪播圖 -->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <h1>1</h1>
        </div>
        <div class="swiper-slide">
          <h1>2</h1>
        </div>
        <div class="swiper-slide">
          <h1>3</h1>
        </div>
        <div class="swiper-slide">
          <h1>4</h1>
        </div>
      </div>
    </div>

  </div>

  <script>
    var mySwiper = new Swiper('.swiper-container',

      {
        // 循環(huán)模式
        loop: true,
        
        pagination: {
          // 自定義分頁器的類名----必填項
          el: '.custom-pagination',

          // 是否可點擊----必填項
          clickable: true,

          // 分頁的類型是自定義的----必填項
          type: 'custom',

          // 自定義特殊類型分頁器,當(dāng)分頁器類型設(shè)置為自定義時可用。
          renderCustom: function (swiper, current, total) {
            //  console.log(current);//1 2 3 4

            // 1、分頁器激活樣式的改變---給自己添加激活樣式并將兄弟的激活樣式移出。
            $('.custom-pagination').children().eq(current - 1).addClass('active').siblings().removeClass('active');

            // 2、分頁器點擊的時候同時切換輪播圖(事件委托)----循環(huán)模式slideToLoop--
            $('.custom-pagination').on('click', 'li', function () {
              mySwiper.slideToLoop($(this).index(), 1000, false)
            })
          }
        },
      })
  </script>
</body>
</html>

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

相關(guān)文章

  • 詳解JSON和JSONP劫持以及解決方法

    詳解JSON和JSONP劫持以及解決方法

    這篇文章主要介紹了詳解JSON和JSONP劫持以及解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • JS+DIV+CSS實現(xiàn)仿表單下拉列表效果

    JS+DIV+CSS實現(xiàn)仿表單下拉列表效果

    這篇文章主要介紹了JS+DIV+CSS實現(xiàn)仿表單下拉列表效果,涉及javascript鼠標(biāo)事件及頁面元素的動態(tài)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-08-08
  • 微信小程序如何實現(xiàn)五星評價功能

    微信小程序如何實現(xiàn)五星評價功能

    這篇文章主要介紹了微信小程序如何實現(xiàn)五星評價功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • 模擬彈出窗口效果,關(guān)閉層之前,不能選擇后面的頁內(nèi)容

    模擬彈出窗口效果,關(guān)閉層之前,不能選擇后面的頁內(nèi)容

    模擬彈出窗口效果,關(guān)閉層之前,不能選擇后面的頁內(nèi)容...
    2007-02-02
  • js獲取當(dāng)前日期時間及其它操作匯總

    js獲取當(dāng)前日期時間及其它操作匯總

    Js獲取當(dāng)前日期時間及其它操作,還有一些自己常用的方法,很好用,也很全。這里推薦給大家,有需要的小伙伴可以參考下。
    2015-04-04
  • javascript設(shè)計模式之module(模塊)模式

    javascript設(shè)計模式之module(模塊)模式

    這篇文章主要為大家詳細(xì)介紹了javascript設(shè)計模式之module(模塊)模式 ,感興趣的小伙伴們可以參考一下
    2016-08-08
  • javascript實現(xiàn)拖拽并替換網(wǎng)頁塊元素

    javascript實現(xiàn)拖拽并替換網(wǎng)頁塊元素

    實現(xiàn)類似于學(xué)生換座位的效果,將網(wǎng)頁內(nèi)的兩個元素通過拖拽的方式互換。
    2009-11-11
  • js模擬實現(xiàn)煙花特效

    js模擬實現(xiàn)煙花特效

    這篇文章主要為大家詳細(xì)介紹了js模擬實現(xiàn)煙花特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • uniapp使用H5調(diào)試時跨域問題解決

    uniapp使用H5調(diào)試時跨域問題解決

    本文主要介紹了uniapp使用H5調(diào)試時跨域問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • 小程序指紋驗證的實現(xiàn)代碼

    小程序指紋驗證的實現(xiàn)代碼

    這篇文章主要介紹了小程序指紋驗證的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12

最新評論

江阴市| 迭部县| 漳州市| 大邑县| 莒南县| 泊头市| 普安县| 林西县| 富平县| 瑞昌市| 长乐市| 乳源| 天柱县| 绥芬河市| 天门市| 江达县| 临邑县| 延寿县| 商丘市| 三亚市| 美姑县| 平乐县| 孟州市| 加查县| 龙江县| 高碑店市| 晴隆县| 慈溪市| 天全县| 安平县| 林州市| 和龙市| 广德县| 百色市| 静乐县| 黄陵县| 依安县| 滕州市| 庐江县| 汾阳市| 敖汉旗|