js 左右滑動代碼


   //鼠標滑動事件
        // 開始按下手機的起點坐標
        var startPoint = null;
        document.addEventListener("touchstart", function (e) {
            var e = e || window.event;
            startPoint = e.touches[0];
        })
        document.addEventListener("touchend", function (e) {
            var e = e || window.event;
            //e.changedTouches能找到離開手機的手指,返回的是一個數組
            var endPoint = e.changedTouches[0];
            //計算終點與起點的差值
            var x = endPoint.clientX - startPoint.clientX;
            var y = endPoint.clientY - startPoint.clientY;
            //設置滑動距離的參考值
                   var d = 100;
            if (Math.abs(x) > d) {
                if (x > 0 && (y < 10 || y > 10)) {
                    console.log("向右滑動");
                    window.location = "/Best";
                } else if (x < 0 && (y < 10 || y > 10)) {
                    console.log("向左滑動");
                    window.location = "/home/Seeview";
                }
            }
            if (Math.abs(y) > d) {
                if (y > 0) {
                    console.log("向下滑動");
                } else {
                    console.log("向上滑動");
                }
            }
        })

轉自  ::  https://blog.csdn.net/gg451516921/article/details/79133416


免責聲明!

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



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