Skip to content

Instantly share code, notes, and snippets.

@rjz
Created December 18, 2011 22:34
Show Gist options
  • Save rjz/1494687 to your computer and use it in GitHub Desktop.
Save rjz/1494687 to your computer and use it in GitHub Desktop.
Javascript screensaver
(function(poll, timeout){
var _idle = false,
_lastActive = 0,
_activeNow = function() {
_lastActive = new Date();
if (_idle) {
$('#screensaver').hide();
_idle = false;
}
},
_poll = function() {
var elapsed = (new Date()) - _lastActive;
if ((elapsed > timeout) && !_idle) {
$('#screensaver').fadeIn('slow');
_idle = true;
}
}
$(window).bind('mousemove click keypress resize focus', _activeNow);
window.setInterval(_poll, poll);
_activeNow();
})(2000, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment