Tel*_*bov 3 javascript google-chrome touch-event
我有一些功能可以防止设备上的触摸事件(在某些特定情况下)。它运行良好,直到最后一次更新 Chrome。
更新后,试图阻止我从中获得document或document.body不再工作的事件,但如果我从某个特定元素侦听事件,它会起作用。
例如:
//this not works
document.addEventListener("touchmove", function(event) {
event.preventDefault();
});
//this one works
document.querySelector(".container").addEventListener("touchmove", function(event) {
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
这不是很方便的行为,因为我在body元素中有很多子元素并且无法更改此结构。
有没有人知道如何让它再次工作,或者它是最新 Chrome 的正确行为?将不胜感激任何帮助,谢谢。
通过此更改,添加到文档中的 touchstart 和 touchmove 侦听器将默认为passive:true(因此对 preventDefault 的调用将被忽略)。
要让它再次工作,passive可以将属性设置为false。
document.addEventListener("touchmove", function(event) {
event.preventDefault();
}, {passive: false});
Run Code Online (Sandbox Code Playgroud)
不确定强制事件处理程序不是被动的是否合理,但无论如何都可以考虑到这一点。
| 归档时间: |
|
| 查看次数: |
1977 次 |
| 最近记录: |