Skip to content

Instantly share code, notes, and snippets.

@wadackel
Created December 14, 2015 14:55
Show Gist options
  • Save wadackel/e961f951fb62c70e8ea2 to your computer and use it in GitHub Desktop.
Save wadackel/e961f951fb62c70e8ea2 to your computer and use it in GitHub Desktop.
ES6 ModulesでrequestAnimationFrameのpolyfill
let lastTime = 0;
const raf =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback){
const currentTime = Date.now();
const timeToCall = Math.max(0, 16 - (currentTime - lastTime));
const id = window.setTimeout(() => { callback(currentTime + timeToCall) }, timeToCall);
lastTime = currentTime + timeToCall;
return id;
};
export default raf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment