File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ toucher是一个面向移动端web开发,通过监听原生事件模拟手势
17
17
* swipeleft:左划
18
18
19
19
#说明
20
- 监听的对象不阻止浏览器默认事件 ,若要用于拖动操作,或滑动更为细腻,可增加preventDefault属性 ,但此时页面是不能通过拖动当前dom进行滚动的!
20
+ 事件触发时不阻止浏览器默认事件 ,若要用于拖动操作,或滑动更为细腻,可在swipe事件中使用“return false;”阻止浏览器默认事件 ,但此时页面是不能通过拖动当前dom进行滚动的!
21
21
#DEMO
22
22
请使用移动设备或使用调试工具模拟移动设备查看 [ demo] ( http://htmlpreview.github.io/?https://github.com/bh-lay/toucher/blob/master/touch.html )
23
23
@@ -26,8 +26,7 @@ toucher是一个面向移动端web开发,通过监听原生事件模拟手势
26
26
27
27
``` javascript
28
28
var myTouch = util .toucher (document .getElementById (' touchBox' ));
29
- // 阻止浏览器默认事件
30
- // myTouch.preventDefault = true;
29
+
31
30
myTouch .on (' singleTap' ,function (e ){
32
31
//
33
32
}).on (' longTap' ,function (e ){
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-6-8 9:6
4
+ * @modified 2014-6-9 16:58
5
5
*
6
6
*/
7
7
8
8
9
9
( function ( global , doc , factoryFn ) {
10
10
var factory = factoryFn ( ) ;
11
-
11
+ //提供window.util.toucher()接口
12
12
global . util = global . util || { } ;
13
13
global . util . toucher = global . util . toucher || factory ;
14
14
//提供CommonJS规范的接口
153
153
newE . moveX = newE . pageX - newE . startX ,
154
154
newE . moveY = newE . pageY - newE . startY
155
155
}
156
- return fn . call ( dom , newE ) ;
156
+ var call_result = fn . call ( dom , newE ) ;
157
+ //若绑定方法返回false,阻止浏览器默认事件
158
+ if ( call_result == false ) {
159
+ e . preventDefault ( ) ;
160
+ e . stopPropagation ( ) ;
161
+ }
162
+
163
+ return call_result ;
157
164
}
158
165
/**
159
166
* 判断swipe方向
261
268
EMIT . call ( this_touch , 'singleTap' , e ) ;
262
269
}
263
270
actionOver ( e ) ;
264
- //是否阻止浏览器默认事件
265
- if ( this_touch . preventDefault ) {
266
- e . preventDefault ( ) ;
267
- e . stopPropagation ( ) ;
268
- }
269
271
}
270
272
271
273
/**
305
307
var param = param || { } ;
306
308
307
309
this . dom = DOM ;
308
- this . preventDefault = ( typeof ( param . preventDefaul ) == 'boolean' ? param . preventDefault : false ) ;
309
310
//监听DOM原生事件
310
311
eventListener . call ( this , this . dom ) ;
311
312
}
You can’t perform that action at this time.
0 commit comments