//Code by RosenChai
$.fn.swipeCatch = function(func1,func2){
var touch_start={},touch_now={},touch_end={},diff={};
var $this = $(this);
$this.off().on('touchstart',function(e){
touch_start.x = e.touches[0].pageX||e.pageX;
touch_start.y = e.touches[0].pageY||e.pageY;
}).on('touchmove',function(e){
touch_now.x = e.touches[0].pageX||e.pageX;
touch_now.y = e.touches[0].pageY||e.pageY;
diff.x = touch_now.x - touch_start.x;
diff.y = touch_now.y - touch_start.y;
if(Math.abs(diff.x)>20){var s=true;}
if(s){e.preventDefault();}
}).on('touchend',function(e){
if(Math.abs(diff.y)<100){
if(diff.x>100){
func2($(this));
}else if(diff.x<-100){
func1($(this));
}
}
});
}
// 使用方法:
//
// $('header').swipeCatch(function(obj){
// //left function
// },function(obj){
// //right function
// });