当我添加事件侦听器以考虑触摸事件时,例如 touchmove 和 touchstart
document.addEventListener("touchstart", function(event){
event.preventDefault();
document.getElementById("fpsCounter").innerHTML = "touch start";
trace("touch start");
}, false);
document.addEventListener("touchmove", function(event){
event.preventDefault();
var x = event.touches[0].pageX - getCanvasOffset().offsetLeft;
var y = event.touches[0].pageY - getCanvasOffset().offsetTop;
document.getElementById("fpsCounter").innerHTML = "touch touchmove "+x+" "+y;
trace("touch touchmove");
}, false);
document.addEventListener("touchend", function(event){
event.preventDefault();
document.getElementById("fpsCounter").innerHTML = "touch end";
trace("touch touch end");
}, false);
document.addEventListener("touchcancel", function(event){
event.preventDefault();
document.getElementById("fpsCounter").innerHTML = "touch cancel";
trace("touch touch cancel");
}, false);
}
touchMove 工作正常,直到我开始向下移动,因为整个 html 页面开始被 safari 向下滚动。当我释放时,html 页面弹回原来的位置。html 页面内的任何元素都不会溢出 ipad 的边界。我怎样才能防止浏览器的拖动 html 页面功能?我尝试 event.preventDefault() 没有运气