Zepto源码之touch模块


;(function($){
   
  var touch = {},
    touchTimeout, tapTimeout, swipeTimeout, longTapTimeout,
    longTapDelay = 750,
    gesture,
    down, up, move,
    eventMap,
    initialized = false

  // 滑动方向
  function swipeDirection(x1, x2, y1, y2) {
   
    // 先判断水平与垂直方向谁的相对位移比较大,如果水平方向大,那就是水平滑动,否则就是垂直滑动
    return Math.abs(x1 - x2) >=
    // 判断完了方向再比较两个手势点位移,通过位移差判断是上下左右滑动
      Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down')
  }

  // 长按
  function longTap() {
   
    // 清空 longTabTimeout 计时器
    longTapTimeout = null
    // 如果 touch.last 存在,则触发 longTap 事件,然后清空 touch 对象,方便下次使用
    if (touch.last) {
      touch.el.trigger('longTap')
      touch = {}
    }
  }

  // 取消长按
  function cancelLongTap() {
   
    // 清空 longTabTimeout 计时器
    if (longTapTimeout) clearTimeout(longTapTimeout)
    longTapTimeout = null
  }

  // 取消全部
  function cancelAll() {
   
    // 清空所有计时器,然后清空 touch 对象,方便下次使用
    if (touchTimeout) clearTimeout(touchTimeout)
    if (tapTimeout) clearTimeout(tapTimeout)
    if (swipeTimeout) clearTimeout(swipeTimeout)
    if (longTapTimeout) clearTimeout(longTapTimeout)
    touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null
    touch = {}
  }

  // 是否为主触点
  function isPrimaryT
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值