-
-
Save jimmont/5543741 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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