jQuery判断移动端屏幕的滑动方向
$('body').on('touchstart', function(e) {
var touch = e.originalEvent,
startX = touch.changedTouches[0].pageX;
startY = touch.changedTouches[0].pageY;
$('body').on('touchmove', function(e) {
touch = e.originalEvent.touches[0] ||
e.originalEvent.changedTouches[0];
if (touch.pageX - startX > 10) {
console.log("右划");
showPrevious();
$('body').off('touchmove');
} else if (touch.pageX - startX < -10) {
console.log("左划");
showNext();
$('body').off('touchmove');
};
if (touch.pageY - startY > 10) {
console.log("下划");
$('body').off('touchmove');
} else if (touch.pageY - startY < -10) {
console.log("上划");
$('body').off('touchmove');
};
});
return false;
}).on('touchend', function() {
$('body').off('touchmove');
});