tags:

views:

135

answers:

3

I'd like to be able to use jQuery to trigger an event if the mouse has been stationary for a certain amount of time.

Any ideas? I'm not even sure where to start!

+1  A: 

Hook up a mousemove() handler on the document and set a timeout. When timeout elapses, do your thing. Whenever the mouse moves again, cancel the timeout so it will fire relative to the last mouse movement.

This is a combination of jQuery and JavaScript.

John K
+1  A: 

There's the idleTimer plugin which could be used for this purpose. And here's a nice demo of the plugin in action.

Darin Dimitrov
I like your solution because it's sensitive to both mouse and keyboard. Also it might come with some implicit cross-browser compatibility benefits.
John K
Nice plugin! :-)
The Elite Gentleman
A: 

jquery 1.4 offers a new method delay() for that

http://api.jquery.com/delay/

luca

related questions