美文网首页
(三)Swiper touch触发条件设置

(三)Swiper touch触发条件设置

作者: 我拥抱着我的未来 | 来源:发表于2018-09-29 14:44 被阅读0次

(1) 本节知识点

  • 触摸距离与slide滑动距离比率: touchRatio 设置的越小越难滑动
  • 无法拖动 : onlyExternal 设置为true就无法滑动
  • 跟随手指 : followFinger 设置为false 手指滑动和页面滑动不同步
  • 定义longSwipes : longSwipesMs
  • 短时间短距离和长时间长距离 : shortSwipes 和longSwipes
  • 触发所需最小拖动距离比例 : longSwipersRadio
  • 允许拖动角度 : touchAngle

(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>

相关文章

  • (三)Swiper touch触发条件设置

    (1) 本节知识点 触摸距离与slide滑动距离比率: touchRatio 设置的越小越难滑动 无法拖动 : o...

  • 火币合约计划委托功能怎么用,可以同时止损止盈吗

    计划委托,指的是预先设置触发条件及其委托价格和数量,当市场最新成交价格达到触发条件时,系统将按提前设置好的委托价和...

  • 02-移动web开发

    一、移动端touch事件 当用户手指放在移动设备在屏幕上滑动会触发的touch事件 touch事件包含三个触摸列表...

  • 02-移动web开发

    一、移动端touch事件 当用户手指放在移动设备在屏幕上滑动会触发的touch事件 touch事件包含三个触摸列表...

  • 中继器实现模糊筛选

    一、添加文本框,命名:1 二、添加中继器,命名:2,并绑定好数据 三、设定筛选条件: 1、设置搜索触发条件: 2、...

  • JavaScript for Mobile

    Touch Events 触摸事件(touch events) touchstart: 手指放到屏幕上的时候触发 ...

  • 实现 ABAP 条件断点的三种方式分享

    所谓条件断点,就是设置在某行语句上的断点,并不总是会触发,而是仅当满足一定条件时才触发。 条件断点的使用场合是什么...

  • Day3 新闻列表页面

    Swiper组件构建轮播图 设置css样式时,注意设置在swiper-item上设置宽度(100%)和高度,同样的...

  • Eclipse设置断点触发的条件

    特别是我们在做循环操作的时候,一堆的循环列表,但是只有某一个值出问题,一次次的循环调试起来很费劲,这个时候,我们可...

  • touch一系列和swiper一起用遇到的问题

    swiper 是滑动,但是如果给当前swiper中的元素,绑定了touch的事件,两者就会冲突。我给的解决方式是,...

网友评论

      本文标题:(三)Swiper touch触发条件设置

      本文链接:https://www.haomeiwen.com/subject/szovoftx.html