(三)Swiper touch触发条件设置

2018-09-29  本文已影响0人  我拥抱着我的未来

(1) 本节知识点

(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">Slide 1</div>
      <div class="swiper-slide">Slide 2</div>
      <div class="swiper-slide">Slide 3</div>
    </div>
  </div>
</body>
<script>
  window.onload = function() {
    var mySwiper = new Swiper('.swiper-container', {
      direction: 'horizontal', //上下滑动,要是横着滑就是horizontal,要是竖着滑vertical
      touchRatio: 0.2, //设置的越小越难以滑动
      onlyExternal: true, //设置成true就无法滑动,默认就是false
      followFinger: false, //跟随手指设置false滑动和手指不同步了
      longSwipesMs: 1000, //定义了当你按下到滑动的一个时间
      longSwipes: false, //是否允许长时间滑动,设置为false那上面的longSwipesMs不起作用
      shortSwipes: true, //是否允许短时间滑动
      longSwipersRadio: 0.9, //相对于容器的最大距离。0.9表示滑动90%的距离才到下一个
      touchAngle: 10, //允许滑动的角度,设置的越小表示越难以滑动
    })
  }
</script>

</html>
上一篇下一篇

猜你喜欢

热点阅读