터치 방향 판단 방법

1130 단어
touch :touchstart、touchend、touchmove
$("body").on("touchstart", function(e) {
        e.preventDefault();
        startX = e.originalEvent.changedTouches[0].pageX,
        startY = e.originalEvent.changedTouches[0].pageY;
});

$("body").on("touchmove", function(e) {
        e.preventDefault();
        moveEndX = e.originalEvent.changedTouches[0].pageX, 
        moveEndY = e.originalEvent.changedTouches[0].pageY, 
        X = moveEndX - startX, 
        Y = moveEndY - startY;
        
        if ( Math.abs(X) > Math.abs(Y) && X > 0 ) {
            alert("left2 right");
        } else if ( Math.abs(X) > Math.abs(Y) && X < 0 ) {
            alert("right2 left");
        }else if ( Math.abs(Y) > Math.abs(X) && Y > 0) {
            alert("top2 bottom");
        }else if ( Math.abs(Y) > Math.abs(X) && Y < 0 ) {
            alert("bottom2 top");
        }else{
            alert("justtouch");
        }
});

다음으로 전송:https://www.cnblogs.com/richardcastle/p/8297400.html

좋은 웹페이지 즐겨찾기