File tree Expand file tree Collapse file tree 3 files changed +26
-24
lines changed Expand file tree Collapse file tree 3 files changed +26
-24
lines changed Original file line number Diff line number Diff line change @@ -4,22 +4,24 @@ toucher
4
4
toucher是一个面向移动端web开发,通过监听原生事件模拟手势事件的库。
5
5
6
6
#目前支持哪些事件
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:滑动结束
18
20
19
21
#说明
20
22
目前尚不支持双指操作的事件,此类事件可能会在下次大的更新之后作为补充加入进来。
21
23
22
- 事件触发时不阻止浏览器默认事件,若要用于拖动操作,或滑动更为细腻,可在swipe事件中使用“return false;”阻止浏览器默认事件,但此时页面是不能通过拖动当前dom进行滚动页面操作 !
24
+ 事件触发时不阻止浏览器默认事件,若要用于拖动操作,或滑动更为细腻,可在swipe事件中使用“return false;”阻止浏览器默认事件!
23
25
24
26
#DEMO
25
27
请使用移动设备或使用调试工具模拟移动设备查看 [ demo] ( http://htmlpreview.github.io/?https://github.com/bh-lay/toucher/blob/master/touch.html )
Original file line number Diff line number Diff line change 1
1
/**
2
2
* @author 剧中人
3
3
* @github https://github.com/bh-lay/toucher
4
- * @modified 2014-8-25 20:23
4
+ * @modified 2015-3-7 01:02
5
5
*
6
6
*/
7
7
146
146
'pageY' : touch . clientY || 0
147
147
} ;
148
148
//为swipe事件增加交互初始位置及移动距离
149
- if ( name == ' swipe' && e . startPosition ) {
149
+ if ( name . match ( / ^ s w i p e / ) && e . startPosition ) {
150
150
newE . startX = e . startPosition [ 'pageX' ] ,
151
151
newE . startY = e . startPosition [ 'pageY' ] ,
152
152
newE . moveX = newE . pageX - newE . startX ,
251
251
eventMark = e ;
252
252
//在原生事件基础上记录初始位置(为swipe事件增加参数传递)
253
253
e . startPosition = {
254
- ' pageX' : x1 ,
255
- ' pageY' : y1
254
+ pageX : x1 ,
255
+ pageY : y1
256
256
} ;
257
257
//断定此次事件为移动事件
258
258
EMIT . call ( this_touch , 'swipe' , e ) ;
259
259
260
260
if ( ! isActive ) {
261
261
return
262
262
}
263
- x2 = e . touches [ 0 ] . pageX
264
- y2 = e . touches [ 0 ] . pageY
263
+ x2 = e . touches [ 0 ] . pageX
264
+ y2 = e . touches [ 0 ] . pageY
265
265
if ( Math . abs ( x1 - x2 ) > 2 || Math . abs ( y1 - y2 ) > 2 ) {
266
266
//断定此次事件为移动手势
267
267
var direction = swipeDirection ( x1 , x2 , y1 , y2 ) ;
Original file line number Diff line number Diff line change 58
58
< body >
59
59
< div class ="consoleCnt ">
60
60
< div class ="console console1 ">
61
- logger< br />
61
+ -- logger-- < br />
62
62
</ div >
63
63
< div class ="console console3 ">
64
- logger< br />
64
+ -- logger-- < br />
65
65
</ div >
66
66
< div class ="console console2 ">
67
- logger< br />
67
+ -- logger-- < br />
68
68
</ div >
69
69
</ div >
70
70
< div id ="toucher ">
94
94
95
95
96
96
var bodyTouch = util . toucher ( $ ( '#toucher' ) [ 0 ] ) ;
97
- bodyTouch . preventDefault = true ;
98
97
99
98
bodyTouch . on ( 'singleTap' , function ( e ) {
100
99
$ ( '.console3' ) . append ( 'singleTap' + I ( ) + '<br/>' ) ;
134
133
'top' :e . moveY ,
135
134
'left' :e . moveX
136
135
} ) ;
136
+ return false ;
137
137
} ) . on ( 'swipeEnd' , '.checkA' , function ( e ) {
138
138
$ ( '.console1' ) . append ( 'swipeEnd<br/>' ) ;
139
139
console . log ( this , e ) ;
165
165
166
166
167
167
$ ( '.consoleCnt' ) . click ( function ( ) {
168
- $ ( '.console' ) . html ( 'logger<br/>' ) ;
168
+ $ ( '.console' ) . html ( '-- logger-- <br/>' ) ;
169
169
} ) ;
170
170
</ script >
171
171
</ body >
172
- </ html >
172
+ </ html >
You can’t perform that action at this time.
0 commit comments