RequestAnimationFrame crossbrowser support
(function(w) {
var lT = 0,
a = ['ms', 'moz', 'webkit', 'o'],
i = a.length;
while( --i > -1 && !w.requestAnimationFrame ){
w.requestAnimationFrame = w[a[i]+'RequestAnimationFrame'];
w.cancelAnimationFrame = w[a[i]+'CancelAnimationFrame']
|| w[a[i]+'CancelRequestAnimationFrame'];
}
if ( !w.requestAnimationFrame ){
w.requestAnimationFrame = function(callback, element) {
var cT = new Date().getTime(),
tTC = Math.max(0, 16 - (cT - lT)),
id = w.setTimeout(function() { callback(cT + tTC); },tTC);
lT = cT + tTC;
return id;
};
}
if ( !w.cancelAnimationFrame ){
w.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
}(window));
Written by Igor Ivanovic
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#