在Chrome73的最新更新中,它们更改了被动事件侦听器与窗口对象上的鼠标滚轮一起工作的方式。基本上,这已经破坏了一些平滑滚动插件,这些插件在Chrome中滚动时会取消传统鼠标滚轮的默认“抖动”。
chrome平台状态的更改如下所示。
https://www.chromestatus.com/features#browsers.chrome.owners%3A%20sahel%40chromium.org
...and在此页面上,它会将您带到页面,其中显示默认值现在相当于以下内容:
`window.addEventListener("wheel", func, {passive: true} );`所以我猜我需要写一个函数来把它改成:
`window.addEventListener("wheel", func, {passive: false} );`https://github.com/sahel-sh/Document-level-passive-wheel-event-listeners/blob/master/Explainer.md
我想作为一个独立的函数来做这件事,而不是遍历我使用的插件的所有代码,试图弄清楚如何以及在哪里做这件事。
有没有人知道如何写一个独立的函数来做这件事?
我做的任何事似乎都不管用。我该如何解决这个问题?
发布于 2019-04-30 06:01:54
尝尝这个
const EVENTS_TO_MODIFY = ['touchstart', 'touchmove', 'touchend', 'touchcancel', 'wheel'];
const originalAddEventListener = document.addEventListener.bind();
document.addEventListener = (type, listener, options, wantsUntrusted) => {
let modOptions = options;
if (EVENTS_TO_MODIFY.includes(type)) {
if (typeof options === 'boolean') {
modOptions = {
capture: options,
passive: false,
};
} else if (typeof options === 'object') {
modOptions = {
...options,
passive: false,
};
}
}
return originalAddEventListener(type, listener, modOptions, wantsUntrusted);
};
const originalRemoveEventListener = document.removeEventListener.bind();
document.removeEventListener = (type, listener, options) => {
let modOptions = options;
if (EVENTS_TO_MODIFY.includes(type)) {
if (typeof options === 'boolean') {
modOptions = {
capture: options,
passive: false,
};
} else if (typeof options === 'object') {
modOptions = {
...options,
passive: false,
};
}
}
return originalRemoveEventListener(type, listener, modOptions);
};https://stackoverflow.com/questions/55251072
复制相似问题