Skip to content

Instantly share code, notes, and snippets.

@jimmont jimmont/rAF.js forked from paulirish/rAF.js
Last active Dec 17, 2015

Embed
What would you like to do?
// paulirish, emoller et al. MIT license
window.requestAnimationFrame = window.requestAnimationFrame || function(callback, element){
var fn, cfn, w = window, lastTime = 0, v, vendors = 'webkit,moz,ms,o'.split(',');
while(!fn && (v = vendors.shift())){
fn = w[v+'RequestAnimationFrame'];
cfn = w[v+'CancelAnimationFrame'] || w[v+'CancelRequestAnimationFrame'];
};
w.requestAnimationFrame = fn || function(callback, element){
var id, currTime = new Date().getTime(), timeToCall = Math.max(0, 16 - (currTime - lastTime));
id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall);
lastTime = currTime + timeToCall;
};
w.cancelAnimationFrame = cfn || w.clearTimeout;
fn(callback, element);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.