requestAnimationFrame Polyfill
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
var requestAnimationFrame = window.requestAnimationFrame || (function() { | |
var timeLast = 0; | |
return window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { | |
var timeCurrent = (new Date()).getTime(), | |
timeDelta; | |
/* Dynamically set the delay on a per-tick basis to more closely match 60fps. */ | |
/* Technique by Erik Moller. MIT license: https://gist.github.com/paulirish/1579671. */ | |
timeDelta = Math.max(0, 16 - (timeCurrent - timeLast)); | |
timeLast = timeCurrent + timeDelta; | |
return setTimeout(function() { callback(timeCurrent + timeDelta); }, timeDelta); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment