【发布时间】:2022-01-04 15:12:54
【问题描述】:
我有两个项目:
-
Bootstrap与jQuery -
materialize-css与Vanilla JS
在对这两个项目进行 Lighthouse 审计时,我曾经在一个项目上收到由 materialize-css 和另一个项目上的 jQuery 引起的警告:
我说“曾经得到”,因为我确实设法为jQuery 修复了它,只需应用这个解决方法:
const opts = (ns) => ... // some code deciding if browser supports passive
$.event.special.touchmove = { setup: function(_, ns, handle) { this.addEventListener('touchmove', handle, opts(ns)) } }
$.event.special.touchstart = { setup: function(_, ns, handle) { this.addEventListener('touchstart', handle, opts(ns)) } }
$.event.special.touchend = { setup: function(_, ns, handle) { this.addEventListener('touchend', handle, opts(ns)) } }
这似乎解决了jQuery 的问题,我不再收到这样的警告,一切似乎都正常。
现在,对于materialize-css,我找到了这个包default-passive-events(来自文档):
基本上每次你都会自动设置 {passive: true } 声明一个新的事件监听器。
不幸的是,由于使用了e.preventDefault(),这个库确实使物化组件因触摸事件而中断...
是否有类似于上述jQuery 解决方法的方法来修复所有materialize-css 添加的事件侦听器?附言它不使用jQuery
【问题讨论】:
标签: javascript jquery google-chrome materialize lighthouse