Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 事件发生后等待x毫秒,重新检查并触发_Javascript_Jquery_Dom - Fatal编程技术网

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);
  }
});