//鼠標滑動事件 // 開始按下手機的起點坐標 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