How can i decrease the number of mouse over triggered events? I still want to use mouse over but with less amount of event triggers.
$(clientFrameWindow.document.body).on("mouseover",function () {
//it should be 15 times slow down than now.
console.log(1);
});
我正在使用 jQuery。 任何帮助将不胜感激。
最佳答案
由于您必须在body
上使用监听器,根据您的评论,我建议您考虑诸如节流或去抖之类的方法。
阅读此内容以获取更多信息:https://css-tricks.com/the-difference-between-throttling-and-debouncing/
这是一个简单的限制实现:https://jsfiddle.net/jonathansampson/m7G64/
我还建议您消除 jQuery 在这方面的开销,只需执行一个 addEventListener('mouseover', function(){})
编辑:此外,由于您希望将其拖放到 body
上,我假设您的操作系统环境中,也许可以使用 mouseenter
事件而不是 鼠标悬停
?肯定更便宜。
关于javascript - 减少鼠标悬停触发事件的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35976281/