Created
April 1, 2024 01:40
-
-
Save tranchausky/06dce21b712bb7bffea2121c15fb89a9 to your computer and use it in GitHub Desktop.
jqueyr auto call function after 5 minus if no event mouse or keyboard in page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let idleTime = 0; | |
// Increment idle time every second | |
setInterval(timerIncrement, 1000); | |
// Reset idle time on mouse or keyboard event | |
$(document).on('mousemove keydown', function() { | |
idleTime = 0; | |
}); | |
function timerIncrement() { | |
idleTime++; | |
if (idleTime > 300) { // 300 seconds = 5 minutes | |
// Call your function here | |
console.log('No activity for 5 minutes'); | |
idleTime = 0; // Reset idle time | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment