Skip to content

Instantly share code, notes, and snippets.

@gpassarelli
Created March 20, 2012 12:49
Show Gist options
  • Save gpassarelli/2134976 to your computer and use it in GitHub Desktop.
Save gpassarelli/2134976 to your computer and use it in GitHub Desktop.
jQuery: Fire Event When User is Idle
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