2012-04-10 105 views

回答

28
//target the entire page, and listen for touch events 
$('html, body').on('touchstart touchmove', function(e){ 
    //prevent native touch activity like scrolling 
    e.preventDefault(); 
}); 

如果有堵塞的触摸事件不会为你工作,你总是可以是这样的:

html, body{ 
    max-width:100%; 
    max-height:100%; 
    overflow:hidden; 
} 
+0

谢谢,你的jQuery代码对我正在尝试做的事很好。 – 2012-04-11 19:42:21

+1

您必须删除touchstart,因为使用它您也禁用了“点击触摸”事件 – 2015-09-30 07:40:51

+0

@MarcoMantovani,这不是必需条件。 – Fresheyeball 2015-09-30 18:44:47

5

我会提供了一块不利用jQuery的,因此下一个“Javascripter”只能复制'n'paste:

var defaultPrevent=function(e){e.preventDefault();} 
document.body.parentElement.addEventListener("touchstart", defaultPrevent); 
document.body.parentElement.addEventListener("touchmove" , defaultPrevent); 
document.body.addEventListener("touchstart", defaultPrevent); 
document.body.addEventListener("touchmove" , defaultPrevent); 
+0

刚刚在Android上进行了测试。 'defaultPreventDefault()似乎不存在,但'preventDefault()'确实有效。 – 2015-07-09 18:07:17

+0

这么多副本面食。这是一个错字。现在更正,谢谢。 – CyberFox 2015-07-10 09:06:00

相关问题