Skip to content

Commit 98c9ed8

Browse files
committed
Merge pull request bh-lay#1 from bh-lay/master
使用新的代码
2 parents ac3b9bf + 4f09863 commit 98c9ed8

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ toucher
44
toucher是一个面向移动端web开发,通过监听原生事件模拟手势事件的库。
55

66
#目前支持哪些事件
7-
8-
* singleTap:轻击
9-
* doubleTap:双击
10-
* longTap:长按
11-
* swipeStart:滑动开始
12-
* swipe:滑动(若阻止浏览器默认事件,滑动过程中会持续触发)
13-
* swipeEnd:滑动结束
14-
* swipeUp:上划
15-
* swipeRight:右划
16-
* swipeDown:下划
17-
* swipeleft:左划
7+
基本事件
8+
* singleTap:轻击
9+
* doubleTap:双击
10+
* longTap:长按
11+
* swipeUp:上划
12+
* swipeRight:右划
13+
* swipeDown:下划
14+
* swipeleft:左划
15+
16+
高级事件
17+
* swipeStart:滑动开始
18+
* swipe:滑动(阻止浏览器默认事件,滑动过程效果更佳)
19+
* swipeEnd:滑动结束
1820

1921
#说明
2022
目前尚不支持双指操作的事件,此类事件可能会在下次大的更新之后作为补充加入进来。
2123

22-
事件触发时不阻止浏览器默认事件,若要用于拖动操作,或滑动更为细腻,可在swipe事件中使用“return false;”阻止浏览器默认事件,但此时页面是不能通过拖动当前dom进行滚动页面操作
24+
事件触发时不阻止浏览器默认事件,若要用于拖动操作,或滑动更为细腻,可在swipe事件中使用“return false;”阻止浏览器默认事件!
2325

2426
#DEMO
2527
请使用移动设备或使用调试工具模拟移动设备查看 [demo](http://htmlpreview.github.io/?https://github.com/bh-lay/toucher/blob/master/touch.html)

asset/toucher.js

Lines changed: 6 additions & 6 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 2014-8-25 20:23
4+
* @modified 2015-3-7 01:02
55
*
66
*/
77

@@ -146,7 +146,7 @@
146146
'pageY' : touch.clientY || 0
147147
};
148148
//为swipe事件增加交互初始位置及移动距离
149-
if(name == 'swipe' && e.startPosition){
149+
if(name.match(/^swipe/) && e.startPosition){
150150
newE.startX = e.startPosition['pageX'],
151151
newE.startY = e.startPosition['pageY'],
152152
newE.moveX = newE.pageX - newE.startX,
@@ -251,17 +251,17 @@
251251
eventMark = e;
252252
//在原生事件基础上记录初始位置(为swipe事件增加参数传递)
253253
e.startPosition = {
254-
'pageX' : x1,
255-
'pageY' : y1
254+
pageX : x1,
255+
pageY : y1
256256
};
257257
//断定此次事件为移动事件
258258
EMIT.call(this_touch,'swipe',e);
259259

260260
if(!isActive){
261261
return
262262
}
263-
x2 = e.touches[0].pageX
264-
y2 = e.touches[0].pageY
263+
x2 = e.touches[0].pageX
264+
y2 = e.touches[0].pageY
265265
if(Math.abs(x1-x2)>2 || Math.abs(y1-y2)>2){
266266
//断定此次事件为移动手势
267267
var direction = swipeDirection(x1, x2, y1, y2);

touch.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
<body>
5959
<div class="consoleCnt">
6060
<div class="console console1">
61-
logger<br/>
61+
--logger--<br/>
6262
</div>
6363
<div class="console console3">
64-
logger<br/>
64+
--logger--<br/>
6565
</div>
6666
<div class="console console2">
67-
logger<br/>
67+
--logger--<br/>
6868
</div>
6969
</div>
7070
<div id="toucher">
@@ -94,7 +94,6 @@
9494

9595

9696
var bodyTouch = util.toucher($('#toucher')[0]);
97-
bodyTouch.preventDefault = true;
9897

9998
bodyTouch.on('singleTap',function(e){
10099
$('.console3').append('singleTap'+I()+'<br/>');
@@ -134,6 +133,7 @@
134133
'top':e.moveY,
135134
'left':e.moveX
136135
});
136+
return false;
137137
}).on('swipeEnd','.checkA',function(e){
138138
$('.console1').append('swipeEnd<br/>');
139139
console.log(this,e);
@@ -165,8 +165,8 @@
165165

166166

167167
$('.consoleCnt').click(function(){
168-
$('.console').html('logger<br/>');
168+
$('.console').html('--logger--<br/>');
169169
});
170170
</script>
171171
</body>
172-
</html>
172+
</html>

0 commit comments

Comments
 (0)