I want an element to appear in case the website has not been used for a while and make it disappear after it is being used again. Is there any way to detect on a website if the mouse has not been moved for awhile?
closed as off-topic by Robert Harvey♦, gnat, Kilian Foth, Dan Pichelman, Bart van Ingen Schenau Sep 2 '13 at 17:55
- This question does not appear to be about software engineering within the scope defined in the help center.
Put an event handler that takes mouse position whenever mouse is moved store it in variable and store the exact time that happened.
Make a timer that runs each lets say each minute and checks if the last stored mouse position and time is older than a minute then make that element you want to appear else make sure the hide that element.
You can set up a timer that expires after the desired amount of time of mouse inactivity, and reinitialize it whenever the mouse is moved.
See this question for an example (
clearTimeout followed by