Last active
August 29, 2015 14:01
-
-
Save jhurliman/576f7faeee0907b3d706 to your computer and use it in GitHub Desktop.
famo.us - Sleep after n milliseconds of no touch/mouse movement
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 Engine = require('famous/core/Engine'); | |
/** | |
* Sleep after n milliseconds of no touch/mouse movement | |
*/ | |
function sleepOnIdle(idleMS) { | |
var lastMoveMS = Date.now(); | |
window.addEventListener('mousemove', _handleMovement, true); | |
window.addEventListener('touchmove', _handleMovement, true); | |
Engine.on('prerender', _checkSleep); | |
function _handleMovement() { | |
lastMoveMS = Date.now(); | |
Engine.setFPSCap(60); | |
} | |
function _checkSleep() { | |
if (Date.now() - lastMoveMS > idleMS && lastMoveMS !== -1) { | |
Engine.setFPSCap(1); | |
lastMoveMS = -1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment