【问题标题】:jQuery: Easy way to trigger "mousestop" eventjQuery:触发“mousestop”事件的简单方法
【发布时间】:2011-02-25 09:57:15
【问题描述】:

嗨,

当鼠标停止移动 x 秒时,我试图调用一个函数。实际上,使用以下代码很容易:

var timer = null;
$(document).mousemove(function(){
  clearTimeout (timer);
  timer = setTimeout(myfunction, 5000);
});

但是 mousemove 事件经常被调用,所以我在 Firefox 中移动鼠标时的处理器负载非常重。有没有一种简单的方法可以用更少的函数调用来做同样的事情???

谢谢! 一月

【问题讨论】:

    标签: jquery timer mouseevent settimeout mousemove


    【解决方案1】:

    使用它并将延迟选项设置为 x 秒

    http://www.richardscarrott.co.uk/posts/view/jquery-mousestop-event

    【讨论】:

    • 我在 jQuery API 搜索中搜索 mousestop 事件! :((谢谢!
    【解决方案2】:

    看看jQuery hoverIntent plugin

    用法与jQuery hover 相同,但事件仅在可配置的短暂延迟后触发。

    $('myselector').hoverIntent(
            function () { HoverIn(); },
            function () { HoverOut(); }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-28
      • 2013-02-04
      • 2010-10-24
      相关资源
      最近更新 更多