Skip to content

Instantly share code, notes, and snippets.

@mmckegg
Created December 9, 2013 00:27
Show Gist options
  • Save mmckegg/7865625 to your computer and use it in GitHub Desktop.
Save mmckegg/7865625 to your computer and use it in GitHub Desktop.
cross browser requestAnimationFrame that works like setInterval (returns a function that will stop loop if called)
module.exports = animate
var requestAnimationFrame =
global.requestAnimationFrame ||
global.webkitRequestAnimationFrame ||
global.mozRequestAnimationFrame ||
global.msRequestAnimationFrame ||
global.oRequestAnimationFrame ||
function(fn, el) {
setTimeout(fn, 1000/60)
}
function animate(tick, el){
animating = true
requestAnimationFrame(iter, el)
function iter(timestamp) {
if (animating){
tick()
requestAnimationFrame(iter, el)
}
}
return function(){
animating = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment