Automatically scroll when mouse is idle

250 views Asked by At

I need to find a way to randomly scroll horizontally and vertically, plus or minus a set number of pixels per second in each dimension, when the mouse has been idle for a set amount of time. Any ideas on how to achieve this?

Thanks in advance,

Robert

1

There are 1 answers

0
Jani Hartikainen On

You can add a mousemove event listener, and each time the mouse moves, you could use setTimeout to start a counter. After the counter has finished you could safely say that the mouse hasn't been moved. Note that you would need to keep resetting the counter if the user continues moving it (ie. with clearTimeout)