var div=document.querySelector("div"); var startX,startY,moveX,moveY,distanceX,distanceY; // 開始觸摸 div.addEventListener("touchstart",function(e){ start... ...
var div=document.querySelector("div"); var startX,startY,moveX,moveY,distanceX,distanceY; // 開始觸摸 div.addEventListener("touchstart",function(e){ startX=e.targetTouches[0].clientX; startY=e.targetTouches[0].clientY; }) // 觸摸滑動 持續觸發 div.addEventListener("touchmove",function(e){ moveX=e.targetTouches[0].clientX; moveY=e.targetTouches[0].clientY; distanceX=moveX-startX; distanceY=moveY-startY; div.style.transform="translate("+distanceX+"px,"+distanceY+"px)"; }); // 觸摸結束 div.addEventListener("touchend",function(e){ })