Created
December 18, 2011 22:34
-
-
Save rjz/1494687 to your computer and use it in GitHub Desktop.
Javascript screensaver
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
(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