Created
March 9, 2015 11:12
-
-
Save gucheen/808f25775551ee5589f7 to your computer and use it in GitHub Desktop.
detect mouse 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
var timeoutID; | |
function setup() { | |
this.addEventListener("mousemove", resetTimer, false); | |
this.addEventListener("mousedown", resetTimer, false); | |
this.addEventListener("keypress", resetTimer, false); | |
this.addEventListener("DOMMouseScroll", resetTimer, false); | |
this.addEventListener("mousewheel", resetTimer, false); | |
this.addEventListener("touchmove", resetTimer, false); | |
this.addEventListener("MSPointerMove", resetTimer, false); | |
startTimer(); | |
} | |
setup(); | |
function startTimer() { | |
// wait 2 seconds before calling goInactive | |
timeoutID = window.setTimeout(goInactive, 2000); | |
} | |
function resetTimer(e) { | |
window.clearTimeout(timeoutID); | |
goActive(); | |
} | |
function goInactive() { | |
// do something | |
} | |
function goActive() { | |
// do something | |
startTimer(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment