在事件发生后等待x毫秒,重新检查并触发 [英] Waiting x milliseconds after an event, recheck and trigger
本文介绍了在事件发生后等待x毫秒,重新检查并触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个 jQuery.event
监听器,一旦触发器将显示另一个隐藏的元素(基本上是翻转)。
I currently have a jQuery.event
listener, which once triggers will display an otherwise hidden element (a rollover, basically).
但是,有没有办法让jQuery等待几毫秒,重新检查以确保鼠标仍然在元素上,然后触发 .show()
事件如果是?
However, is there a way I can get jQuery to wait a few milliseconds, recheck to ensure the mouse is still over the element and then trigger the .show()
event if it is?
我目前有:
$("#who-mousearea").mouseenter(function(){
$("a#who-edit").fadeIn();
}).mouseleave(function(){
$("a#who-edit").fadeOut();
});
我明白我可以使用setTimeout,但这只会延迟淡入淡出所需的时间元件。
I understand I could use setTimeout, however this would just delay the time it takes to fadeIn() the element.
任何人都有一个如何实现这个想法?
Anyone have an idea on how to achieve this?
推荐答案
var timeout = null;
$("#who-mousearea").mouseenter(function(){
timeout = setTimeout(function() {
timeout = null;
$("a#who-edit").fadeIn();
}, 50);
}).mouseleave(function(){
if (timeout == null) {
$("a#who-edit").fadeOut();
}
else {
clearTimeout(timeout);
}
});
这篇关于在事件发生后等待x毫秒,重新检查并触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文