jq判断触屏左右滑动方向

$('body').on('touchstart', '.slide-box>ul>li', function(e) {
var touch = e.originalEvent,
startX = touch.changedTouches[0].pageX;

$(this).on('touchmove', function(e) {
e.preventDefault();
touch = e.originalEvent.touches[0] ||
e.originalEvent.changedTouches[0];
if (touch.pageX - startX > 20) {//向左
$('#preBtn').click();
$(this).off('touchmove');

} else if (touch.pageX - startX < -20) {//向右

$('#nextBtn').click();
            $(this).off('touchmove');

};

});

// Return false to prevent image
// highlighting on Android
//return false;

}).on('touchend', function() {
$(this).off('touchmove');
});
posted @ 2017-05-27 14:59  泥娃拉拉  阅读(2351)  评论(0编辑  收藏  举报