gpt4 book ai didi

javascript - 如何使用 javascript/jquery 禁用鼠标悬停事件?

转载 作者:行者123 更新时间:2023-11-28 11:06:03 25 4
gpt4 key购买 nike

在我的代码中,当用户第一次将鼠标悬停在 div 上时,函数会执行,该函数大约需要 30 秒才能完成,在这 30 秒内,如果用户再次将鼠标悬停在同一个 div 上,该函数会再次执行,所以我想禁用鼠标悬停第二次事件。是否有任何 javascript 或 jquery 代码可以禁用该 div 中的偶数?谢谢,任何帮助将不胜感激。

最佳答案

使用 jQuery 的 on() 和 off() 以及某种回调,例如:

$("#myElementID").on('mouseover', myFunction);

myFunction(e) {
var myElement = e.target;
myElement.off('mouseover', myFunction);
//do something that takes 30 seconds
myElement.animate({top: 1000}, 30000, function() { //callback
myElement.on('mouseover', myFunction);
});
}

关于javascript - 如何使用 javascript/jquery 禁用鼠标悬停事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11295221/

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