touch events stop firing when dragging down on mobile Safari
When i add event listeners to account for touch events such as touchmove and 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 works fine untill i start moving down, since the whole html page starts getting scrolled down by safari. When I release, the html page bounces back to its original position. No elements inside the html page spill outside of the boundry of the ipad. How could i prevent the browser's dragging html page functionality? i tries event.preventDefault() with no luck
您可以尝试取消该事件(仅使用preventDefault进行移动)
event.cancelBubble = true;
event.returnValue = false;
if (event.stopPropagation) event.stopPropagation();
if (event.preventDefault) event.preventDefault();
链接地址: http://www.djcxy.com/p/95582.html