prefixRequestAnimationFrameLegacy
by Julien Etienne
HTML
<div id='results'></div>
JavaScript
/**
* Fully tested & works for all browsers.
* The un-prefixed function is prefered first, since several browsers support both.
* Uses Paul Irish's fallback for legacy support.
* @see {@link http://www.paulirish.com/2011/requestanimationframe-for-smart-animating}
* @see {@Link https://gist.github.com/julienetie/bd8514854027a6483c13}
* @Author Julien Etienne.
* @License MIT.
* @return {Function} - requestAnimationFrame functioin.
*/
function prefixRequestAnimationFrameLegacy() {
var eAF = 'equestAnimationFrame',
reAF = 'R' + eAF,
rAF = window['r' + eAF] || window[['moz', 'webkit'].filter(function(vendor) {
if (window[vendor + reAF] !== undefined)
return vendor;
}) + reAF] || function(callback, element) {
var currTime = new Date().getTime(),
timeToCall = Math.max(0, 16 - (currTime - lastTime)),
id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
return rAF;
}
var whatIsIt = prefixRequestAnimationFrameLegacy();
var div = document.getElementById('results');
div.innerHTML = whatIsIt;