Swiper(四) Swiper禁止滑动和前进后退

(1) 本节知识点

  • noSwiping 禁止滑屏
    • noSwiping
    • noSwipingClass
  • 前进后退按钮
    • nextButton
    • prevButton

(2) 代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <link rel="stylesheet" href="css/swiper.min.css" />
    <script src="js/swiper.min.js"></script>
  </head>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }

    .swiper-container {
      width: 800px;
      height: 300px;
      border: 10px solid #ccc;
    }

    .swiper-slide {
      font-size: 50px;
    }

    .swiper-slide:nth-of-type(1) {
      background: yellow;
    }

    .swiper-slide:nth-of-type(2) {
      background: blue;
    }

    .swiper-slide:nth-of-type(3) {
      background: red;
    }
  </style>

  <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 3</div>
      </div>
    </div>
    <button class="prev">prev</button>
    <button class="next">next</button>
  </body>
  <script>
    window.onload = function () {
      var mySwiper = new Swiper('.swiper-container', {
        direction: 'horizontal', //上下滑动,要是横着滑就是horizontal,要是竖着滑vertical
        noSwiping: true, //必须配合swiper-no-swiping,哪个滑块不需要滑动,就加这个类
        noSwipingClass: 'stop', //这个属性就是为了防止记不住上面那个类名。那我自己定义一个类名来替换,设置后swiper-no-swiping就没有任何效果
        nextButton: '.next', //下一个按钮可以放在容器的外面
        prevButton: '.prev', //上一个按钮可以放在容器的外面
      })
    }
  </script>
</html>

文章作者: 雾烟云
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 雾烟云 !
  目录