Created
March 20, 2012 12:49
-
-
Save gpassarelli/2134976 to your computer and use it in GitHub Desktop.
jQuery: Fire Event When User is Idle
This file contains hidden or 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
idleTimer = null; | |
idleState = false; | |
idleWait = 2000; | |
(function ($) { | |
$(document).ready(function () { | |
$('*').bind('mousemove keydown scroll', function () { | |
clearTimeout(idleTimer); | |
if (idleState == true) { | |
// Reactivated event | |
$("body").append("<p>Welcome Back.</p>"); | |
} | |
idleState = false; | |
idleTimer = setTimeout(function () { | |
// Idle Event | |
$("body").append("<p>You've been idle for " + idleWait/1000 + " seconds.</p>"); | |
idleState = true; }, idleWait); | |
}); | |
$("body").trigger("mousemove"); | |
}); | |
}) (jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment