Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Last active August 29, 2015 14:01
Show Gist options
  • Save jhurliman/576f7faeee0907b3d706 to your computer and use it in GitHub Desktop.
Save jhurliman/576f7faeee0907b3d706 to your computer and use it in GitHub Desktop.
famo.us - Sleep after n milliseconds of no touch/mouse movement
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