方法一: jquery方法 movePage($('body')); function movePage(dom) { var startY, moveY, moveSpave; dom.on("touchstart", function(e) { startY = e.originalEvent. ...
方法一:
jquery方法
movePage($('body'));
function movePage(dom) {
var startY, moveY, moveSpave;
dom.on("touchstart", function(e) {
startY = e.originalEvent.touches[0].pageY; return startY;
});
dom.on("touchmove", function(e) {
moveY = e.originalEvent.touches[0].pageY;
moveSpave = startY - moveY;
if (moveSpave > 15) {
location.href = 'main.html'; /* 跳轉到main.html */
}
});
}
方法二:
原生方法
var strat,move,num; /*定義三個變數, 記錄開始、結束距離頂部的距離*/
div_demo.addEventListener("touchstart", function (e){ /*觸摸開始*/
console.log("觸摸開始")
// console.log(e)
start = e.touches[0].pageY;
console.log(start) /*得出剛觸屏時距離頁面頂部的距離*/
})
div_demo.addEventListener("touchmove", function (e){ /*觸摸移動*/
console.log("觸摸移動")
// console.log(e)
move = e.touches[0].pageY;
console.log(move) /*得出觸屏結束後距離頁面頂部的距離*/
})
div_demo.addEventListener("touchend", function (e){ /*觸摸結束*/
console.log("觸摸結束")
// console.log(e)
num = start - move ; /*得出開始和結束距離頁面頂部的差值*/
if(num>15){
location.href="main.html" /* 跳轉到main.html */
}
})