给jquery 添加触屏事件,上下左右 touchwipe插件
2015-01-25 23:24
447 查看
touchwipe.js
使用方法:
$('html').touchwipe({
wipeLeft:function(){
alert('左');
},
wipeRight:function(){
alert('右');
},
wipeUp:function(){
alert('下');
},
wipeDown:function(){
alert('上');
},
preventDefaultEvents:true
});
(function($){$.fn.touchwipe=function(settings){var config={min_move_x:20,min_move_y:20,wipeLeft:function(){},wipeRight:function(){},wipeUp:function(){},wipeDown:function(){},preventDefaultEvents:true};if(settings)$.extend(config,settings);this.each(function(){var startX;var startY;var isMoving=false;function cancelTouch(){this.removeEventListener('touchmove',onTouchMove);startX=null;isMoving=false}function onTouchMove(e){if(config.preventDefaultEvents){e.preventDefault()}if(isMoving){var x=e.touches[0].pageX;var y=e.touches[0].pageY;var dx=startX-x;var dy=startY-y;if(Math.abs(dx)>=config.min_move_x){cancelTouch();if(dx>0){config.wipeLeft()}else{config.wipeRight()}}else if(Math.abs(dy)>=config.min_move_y){cancelTouch();if(dy>0){config.wipeDown()}else{config.wipeUp()}}}}function onTouchStart(e){if(e.touches.length==1){startX=e.touches[0].pageX;startY=e.touches[0].pageY;isMoving=true;this.addEventListener('touchmove',onTouchMove,false)}}if('ontouchstart'in document.documentElement){this.addEventListener('touchstart',onTouchStart,false)}});return this}})(jQuery);
使用方法:
$('html').touchwipe({
wipeLeft:function(){
alert('左');
},
wipeRight:function(){
alert('右');
},
wipeUp:function(){
alert('下');
},
wipeDown:function(){
alert('上');
},
preventDefaultEvents:true
});
相关文章推荐
- jQuery -- touch事件之滑动判断(左右上下方向)
- jQuery -- touch事件之滑动判断(左右上下方向)
- html5 touch事件实现触屏页面上下滑动(二)
- jquery插件dataTable. 添加一行记录---触发click()事件
- 写几款Jquery插件 (评分,拖拽分页(可分上下左右))
- jQuery实现select多选框左右添加,包括双击事件
- fxMarquee - jQuery内容滚动插件实现上下左右滚动
- html5 touch事件实现触屏页面上下滑动(一)
- html5 touch事件实现触屏页面上下滑动(一)
- 移动开发中的上下左右滑动插件jquery.swipe.js非常经典的啊!
- jQuery -- touch事件之左右切换元素
- 【转载】移动开发中的上下左右滑动插件jquery.swipe.js
- 43个有关于Touch事件的jQuery插件
- 移动开发中的上下左右滑动插件jquery.swipe.js
- JQuery快速添加/移除插件EasyInsert的简单取值、自动添加或移除多行标签、自动添加事件
- jQuery插件---MultiSelects(左右选框)
- document.ready 与 updatepanel 害死人(Jquery插件失效,Autocomplate事件失效,Jquery事件第一次有效,单击按钮后就时效)
- MyEclipse6.0中使用aptana插件,添加jquery提示功能
- javascript上下左右定时滚动插件
- jQuery为动态生成的select元素添加事件