Skip to content

Commit

Permalink
Updating requestAnimationFrame polyfill for no particular reason
Browse files Browse the repository at this point in the history
  • Loading branch information
darsain committed Nov 29, 2012
1 parent 610047c commit c6452ac
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions jquery.motio.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

var pluginName = 'motio',
namespace = 'plugin_' + pluginName,
rAF;
cAF = window.cancelAnimationFrame || window.cancelRequestAnimationFrame,
rAF = window.requestAnimationFrame;

// Plugin "class"
function Plugin( frame, options ){
Expand Down Expand Up @@ -539,25 +540,29 @@


// local requestAnimationFrame polyfill
(function(){

var lastTime = 0,
vendors = ['ms', 'moz', 'webkit', 'o'];

for( var x = 0; x < vendors.length && !rAF; ++x ){
rAF = window[vendors[x]+'RequestAnimationFrame'];
(function (w) {
var vendors = ['ms', 'moz', 'webkit', 'o'],
lastTime = 0;

// For a more accurate WindowAnimationTiming interface implementation, ditch the native
// requestAnimationFrame when cancelAnimationFrame is not present (older versions of Firefox)
for(var x = 0; x < vendors.length && !cAF; ++x) {
cAF = w[vendors[x]+'CancelAnimationFrame'] || w[vendors[x]+'CancelRequestAnimationFrame'];
rAF = cAF && w[vendors[x]+'RequestAnimationFrame'];
}

if( !rAF ){
rAF = function( callback, element ){
var currTime = new Date().getTime(),
timeToCall = Math.max(0, 16 - ( currTime - lastTime ));
if (!cAF) {
rAF = function (callback) {
var currTime = +new Date(),
timeToCall = Math.max(0, 16 - (currTime - lastTime));
lastTime = currTime + timeToCall;
return setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
return w.setTimeout(function () { callback(currTime + timeToCall); }, timeToCall);
};
}


}());
cAF = function (id) {
clearTimeout(id);
};
}
}(window));

})(jQuery);

0 comments on commit c6452ac

Please sign in to comment.