JQuery: an easy way to fire the "mousestop" event

Hi

I try to call a function when the mouse stops moving for seconds. This is actually pretty easy with the following code:

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

But the mousemove event is triggered very often, so I get a pretty heavy CPU load in Firefox when moving the mouse. Is there an easy way to do the same with smaller function calls ???

Thanx! Jan

+3
source share
2 answers

Use this and set the delay option to x seconds

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

0
source

Take a look at the jQuery hoverIntent plugin

, jQuery hover, .

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

Source: https://habr.com/ru/post/1794665/


All Articles