Reputation: 28137
I use the function mousemove({}). I want this mousemove function to be called only if it was last called at least 1second ago. I know I may use some kind of timer and put a condition
if( cur_time - last_time > 1)
do_the_stuff();
Upvotes: 1
Views: 183
Reputation: 237845
That sounds like a good approach. Your code should look something like this:
var last_moved;
$(document).mousemove(function(e){
if (!last_moved || (e.timeStamp - last_moved > 1000)) {
do_the_stuff();
last_moved = e.timeStamp;
}
});
See a working example on jsFiddle.
Upvotes: 2
Reputation: 5662
No that seems to be the best way to do it. Put that statement within the mousemove and you should get what you need.
Upvotes: 0