乱码乱a∨中文字幕,在线免费激情视频,亚洲欧美久久夜夜潮,国产在线网址

  1. <sub id="hjl7n"></sub>

    1. <sub id="hjl7n"></sub>

      <legend id="hjl7n"></legend>

      當(dāng)前位置:首頁 >  站長 >  編程技術(shù) >  正文

      swiper自定義分頁器的樣式

       2020-11-10 14:29  來源: 腳本之家   我來投稿 撤稿糾錯

        阿里云優(yōu)惠券 先領(lǐng)券再下單

      這篇文章主要為大家詳細(xì)介紹了swiper自定義分頁器的樣式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

      js主要代碼

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

           // 是否可點(diǎn)擊----必填項(xiàng)
           clickable: true,

           // 分頁的類型是自定義的----必填項(xiàng)
          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' 圓點(diǎn)(默認(rèn))

      ‘fraction' 分式

      ‘progressbar' 進(jìn)度條

      ‘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" href="  <script src="  <script src=">

        <!--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;
          }

          /* 點(diǎn)擊的激活樣式 */
          .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: {
                // 自定義分頁器的類名----必填項(xiàng)
                el: '.custom-pagination',

                // 是否可點(diǎn)擊----必填項(xiàng)
                clickable: true,

                // 分頁的類型是自定義的----必填項(xiàng)
                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、分頁器點(diǎn)擊的時候同時切換輪播圖(事件委托)----循環(huán)模式slideToLoop--
                  $('.custom-pagination').on('click', 'li', function () {
                    mySwiper.slideToLoop($(this).index(), 1000, false)
                  })
                }
              },
            })
        </script>
      </body>
      </html>

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

      來源:腳本之家

      鏈接:https://www.jb51.net/article/195530.htm

      申請創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

      相關(guān)標(biāo)簽
      javascript技巧

      相關(guān)文章

      熱門排行

      信息推薦