I need to detect that the user is not moving the cursor (mouse) with jquery so that after x seconds I show him a modal window. I know the mousemove function exists but I need the opposite of this. Thanks.
EDITED
Is there a possibility to stop the setTimeout() after displaying the modal?
You can make a timeout with the function you comment, making it reset every time you move the mouse. If I didn't move it in x time, the function you wanted would skip:
Create a new function in Jquery to determine if the mouse is active inside the
document
, use atimeout
to determine the time, example (execute it, put the cursor in the white space of the snipped and wait 5 seconds):I leave you an example of the function you ask for with the interaction of adding it or removing it. I hope it serves as an example for you.
You can make use of the same javascript functions as setTimeout or setInterval, storing the last date you moved the cursor and then checking that the time you want has passed to execute another action
I am using the following function, which captures the mouse movement in a "move" variable, if after a minute there is no movement, then it executes an "exit" function in the "usersControl.php" file, to redirect to the index