开发者

jQuery: Easy way to trigger "mousestop" event

开发者 https://www.devze.com 2023-02-13 04:15 出处:网络
HI, I\'m trying to call a function when the mouse stopped moving for x seconds. Actually thats pretty easy with the following code:

HI,

I'm trying to call a function when the mouse stopped moving for x seconds. Actually thats pretty easy with the following code:

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

But the mousemove开发者_Python百科 event is called very often, so I get a pretty heavy processor load in Firefox while moving the mouse. Is there an easy way to do the same thing with less function calls???

Thanx! Jan


Use this and set the delay option for x seconds

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


Take a look at the jQuery hoverIntent plugin

Usage is the same as jQuery hover, but the event only fires after a short, configurable delay.

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

精彩评论

暂无评论...
验证码 换一张
取 消