Javascript 事件发生后等待x毫秒,重新检查并触发
我目前有一个Javascript 事件发生后等待x毫秒,重新检查并触发,javascript,jquery,dom,Javascript,Jquery,Dom,我目前有一个jQuery.event监听器,它一旦触发就会显示一个隐藏的元素(基本上是滚动) 但是,有没有办法让jQuery等待几毫秒,重新检查以确保鼠标仍在元素上,然后触发.show()事件(如果是) 我目前有: $("#who-mousearea").mouseenter(function(){ $("a#who-edit").fadeIn(); }).mouseleave(function(){ $("a#who-edit").fadeOut(); });
jQuery.event
监听器,它一旦触发就会显示一个隐藏的元素(基本上是滚动)
但是,有没有办法让jQuery等待几毫秒,重新检查以确保鼠标仍在元素上,然后触发.show()
事件(如果是)
我目前有:
$("#who-mousearea").mouseenter(function(){
$("a#who-edit").fadeIn();
}).mouseleave(function(){
$("a#who-edit").fadeOut();
});
我知道我可以使用setTimeout,但是这只会延迟fadeIn()元素所需的时间
有人知道如何实现这一点吗?清除鼠标离开时的超时
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);
}
});