;(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
Zepto源码之touch模块
最新推荐文章于 2020-02-01 15:57:02 发布