Js touchg事件在移动端网页中左右滑动效果

参考网址:

https://www.cnblogs.com/pingfan1990/p/5447404.html

https://www.cnblogs.com/liangshaojiang/p/9013912.html

//滑动
        $("body").on("touchstart", function(e) {
            if(e.target.tagName == 'A') {
                location.href = $(".lightSpeedIn a").attr("href")
            }//判断如果有a标签,可以执行href跳转
            startX = e.originalEvent.changedTouches[0].pageX,
                startY = e.originalEvent.changedTouches[0].pageY;
        });
        $("body").on("touchend", function(e) {
            // 判断默认行为是否可以被禁用
            if(e.cancelable) {
                // 判断默认行为是否已经被禁用
                if(!e.defaultPrevented) {
                    e.preventDefault();
                }
            }
            moveEndX = e.originalEvent.changedTouches[0].pageX,
                moveEndY = e.originalEvent.changedTouches[0].pageY,
                X = moveEndX - startX,
                Y = moveEndY - startY;
            //左滑
            if(X < 0) {
                location.href = "baom.html"
            }
        });

此段代码过于灵敏~不推荐使用

posted @ 2019-09-09 15:57  夏小夏吖  阅读(849)  评论(0编辑  收藏  举报