【问题标题】:Waiting x milliseconds after an event, recheck and trigger事件发生后等待 x 毫秒,重新检查并触发
【发布时间】:2010-12-01 16:59:16
【问题描述】:

我目前有一个jQuery.event 监听器,一旦触发它就会显示一个隐藏的元素(基本上是翻转)。

但是,有没有办法让 jQuery 等待几毫秒,重新检查以确保鼠标仍在元素上方,然后触发 .show() 事件(如果是)?

我目前有:

$("#who-mousearea").mouseenter(function(){  
    $("a#who-edit").fadeIn();  
}).mouseleave(function(){  
    $("a#who-edit").fadeOut();  
});

我知道我可以使用 setTimeout,但这只会延迟 fadeIn() 元素所需的时间。

有人知道如何实现这一目标吗?

【问题讨论】:

    标签: javascript jquery dom


    【解决方案1】:
    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);
      }
    });
    

    【讨论】:

      【解决方案2】:

      清除鼠标离开超时。

      【讨论】:

        猜你喜欢
        • 2019-06-05
        • 1970-01-01
        • 1970-01-01
        • 2014-09-30
        • 2019-06-11
        • 2013-04-25
        • 2015-07-12
        • 2012-02-23
        • 2012-07-09
        相关资源
        最近更新 更多