gpt4 book ai didi

javascript - 考虑将事件处理程序标记为 'passive' 以使页面更具响应性

转载 作者:IT老高 更新时间:2023-10-28 13:14:53 27 4
gpt4 key购买 nike

我正在使用锤子进行拖动,并且在加载其他内容时它变得不稳定,正如此警告消息所告诉我的那样。

Handling of 'touchstart' input event was delayed for X ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responsive.

所以我尝试像这样向听众添加“被动”

Hammer(element[0]).on("touchstart", function(ev) {
// stuff
}, {
passive: true
});

但我仍然收到此警告。

最佳答案

对于第一次收到此警告的用户,这是由于最近(2016 年夏季)在浏览器中实现的称为被动事件监听器 的前沿功能。来自 https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md :

Passive event listeners are a new feature in the DOM spec that enabledevelopers to opt-in to better scroll performance by eliminating theneed for scrolling to block on touch and wheel event listeners.Developers can annotate touch and wheel listeners with {passive: true}to indicate that they will never invoke preventDefault. This featureshipped in Chrome 51, Firefox 49 and landed in WebKit. For full official explanation read more here.

另请参阅:What are passive event listeners?

您可能需要等待 .js 库实现支持。

如果您通过 JavaScript 库间接处理事件,您可能会受制于该特定库对该功能的支持。截至 2019 年 12 月,似乎没有任何主要库已实现支持。一些例子:

关于javascript - 考虑将事件处理程序标记为 'passive' 以使页面更具响应性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39152877/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com