移动端项目中,在滚动的时候,会报出以下提示:

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.
See https://www.chromestatus.com/features/5093566007214080

解决

  1. touch的事件监听方法上绑定第三个参数{ passive: false }

    通过传递 passive 为 false 来明确告诉浏览器:事件处理程序调用 preventDefault 来阻止默认滑动行为。
target.addEventListener('touch', function () {

}, { passive: false });
  1. 在 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

04-15 01:51