码迷,mamicode.com
首页 > 其他好文 > 详细

/touch滑屏事件

时间:2018-02-10 15:55:53      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:star   otto   art   hang   事件   top   original   amp   rtx   

//touch滑屏事件

 

    var windowHeight = $(window).height(),
    $body = $("body");
    $body.css("height", windowHeight);

    $("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 > 10 ) {
            alert("left 2 right");
        }
        else if ( Math.abs(X) > Math.abs(Y) && X < 10 ) {
            alert("right 2 left");
        }
        else if ( Math.abs(Y) > Math.abs(X) && Y > 10) {
            alert("top 2 bottom");
        }
        else if ( Math.abs(Y) > Math.abs(X) && Y < 10 ) {
            alert("bottom 2 top");
        }
        else{
            alert("just touch");
        }
    });

/touch滑屏事件

标签:star   otto   art   hang   事件   top   original   amp   rtx   

原文地址:https://www.cnblogs.com/xzzzys/p/8438801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!