移动端页面滑动时候警告: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 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

移动端页面滑动时候警告:Unable to preventDefault inside passive event listener due to target being treated as passive.

上一篇:20155208徐子涵 2016-2017-2 《Java程序设计》第10周学习总结


下一篇:android XMl 解析神奇xstream 四: 将复杂的xml文件解析为对象