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');
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM