Skip to content

Commit be52917

Browse files
committed
使用优化后的代码
见master 6e5cf93
1 parent f63ba33 commit be52917

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

javascript/toucher.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author 剧中人
33
* @github https://github.com/bh-lay/toucher
4-
* @modified 2015-6-5 09:37
4+
* @modified 2015-6-23 00:25
55
*
66
*/
77

@@ -201,11 +201,16 @@
201201
clearTimeout(touchDelay);
202202
}
203203

204+
205+
//断定此次事件为轻击事件
206+
function isSingleTap(){
207+
actionOver();
208+
EMIT.call(this_touch,'singleTap',eventMark);
209+
}
204210
//触屏开始
205211
function touchStart(e){
206212
//缓存事件
207213
eventMark = e;
208-
209214
x1 = e.touches[0].pageX;
210215
y1 = e.touches[0].pageY;
211216
x2 = 0;
@@ -229,12 +234,12 @@
229234
return
230235
}
231236
var now = new Date();
232-
if(now - lastTouchTime > 260){
233-
touchDelay = setTimeout(function(){
234-
//断定此次事件为轻击事件
235-
actionOver();
236-
EMIT.call(this_touch,'singleTap',eventMark);
237-
},250);
237+
//若未监听doubleTap,直接响应
238+
if(!this_touch._events.doubleTap || this_touch._events.doubleTap.length == 0){
239+
isSingleTap();
240+
}else if(now - lastTouchTime > 200){
241+
//延迟响应
242+
touchDelay = setTimeout(isSingleTap,190);
238243
}else{
239244
clearTimeout(touchDelay);
240245
actionOver(e);
@@ -259,16 +264,15 @@
259264
if(!isActive){
260265
return
261266
}
262-
x2 = e.touches[0].pageX
263-
y2 = e.touches[0].pageY
267+
x2 = e.touches[0].pageX
268+
y2 = e.touches[0].pageY
264269
if(Math.abs(x1-x2)>2 || Math.abs(y1-y2)>2){
265270
//断定此次事件为移动手势
266271
var direction = swipeDirection(x1, x2, y1, y2);
267272
EMIT.call(this_touch,'swipe' + direction,e);
268273
}else{
269274
//断定此次事件为轻击事件
270-
actionOver(e);
271-
EMIT.call(this_touch,'singleTap',e);
275+
isSingleTap();
272276
}
273277
actionOver(e);
274278
}
@@ -320,4 +324,4 @@
320324
return function (dom){
321325
return new touch(dom);
322326
};
323-
});
327+
});

0 commit comments

Comments
 (0)