我一直试图停止在触摸设备中滚动,我使用 touchmove
事件为:
$('body').on('touchmove.sidebar', function(e){
e.preventDefault();
});
在chrome控制台中,我看到警告:
由于目标被视为被动,因此无法阻止被动事件侦听器内的默认 . 请参阅https://www.chromestatus.com/features/5093566007214080
在github上,建议使用 touch-action: none
而不是 preventDefault()
. 所以我的问题是:
- 我应该同时使用
preventDefault()
和touch-action: none
还是后者?后者适用于Firefox和其他触控浏览器吗?
1 回答
您在Chrome中看到警告的原因是,默认情况下,Chrome版本54是为了增强滚动性能,它假定不会为文档级别调用preventDefault() .
在简单的js中我没有使用过jquery:
Check this answer out
现在回答你的问题:
你不需要两者,任何一个都足够了 . 根据您的要求决定 .
检查caniuse如果您对浏览器支持
touch-action
感到满意,请选择它 .如果您对它提供的支持不满意,请使用preventDefault()方法 .
请查看此链接以获取更多信息:https://www.html5rocks.com/en/mobile/touchandmouse/