移动端页面滑动时候警告:Unable to preventDefault inside passive event listener due to target being treated as pa
Posted cckui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了移动端页面滑动时候警告:Unable to preventDefault inside passive event listener due to target being treated as pa相关的知识,希望对你有一定的参考价值。
移动端项目中,在滚动的时候,会报出以下提示:
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.
See https://www.chromestatus.com/features/5093566007214080
解决
- 在
touch
的事件监听方法上绑定第三个参数{ passive: false }
,
通过传递 passive 为 false 来明确告诉浏览器:事件处理程序调用 preventDefault 来阻止默认滑动行为。
target.addEventListener('touch', function () {
}, { passive: false });
- 在 CSS 中全局使用:
* {
touch-action: pan-y;
}
touch-action
的使用方法见:https://developer.mozilla.org/zh-CN/docs/Web/CSS/touch-action
参考:
https://juejin.im/post/5ad804c1f265da504547fe68
https://www.jianshu.com/p/04bf173826aa
以上是关于移动端页面滑动时候警告:Unable to preventDefault inside passive event listener due to target being treated as pa的主要内容,如果未能解决你的问题,请参考以下文章
Unable to preventDefault inside passive event listener due to target being treated as passive?
移动端报错: Unable to preventDefault inside passive event listener due to target being treated as passive
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as
spark 启动时候报 Unable to load native-hadoop library for your platform 警告
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as
mui执行滑动事件: Unable to preventDefault inside passive event listener