1 // Source: https://github.com/darius/requestAnimationFrame/blob/master/requestAnimationFrame.js
2 // Adapted from https://gist.github.com/paulirish/1579671 which derived from
3 // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
4 // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
6 // requestAnimationFrame polyfill by Erik Möller.
7 // Fixes from Paul Irish, Tino Zijdel, Andrew Mao, Klemen Slavič, Darius Bacon
17 * @return {number} the current Date
19 Date.now = function() { return new Date().getTime(); };
20 Date['now'] = Date.now;
23 var vendors = ['webkit', 'moz'];
24 for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
26 window.requestAnimationFrame = window[vp + 'RequestAnimationFrame'];
27 window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] ||
28 window[vp + 'CancelRequestAnimationFrame']);
29 window['requestAnimationFrame'] = window.requestAnimationFrame;
30 window['cancelAnimationFrame'] = window.cancelAnimationFrame;
33 if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || !window.requestAnimationFrame || !window.cancelAnimationFrame) {
36 * requestAnimationFrame polyfill.
37 * @param {!Function} callback the callback function.
39 window.requestAnimationFrame = function(callback) {
41 var nextTime = Math.max(lastTime + 16, now);
42 return setTimeout(function() { callback(lastTime = nextTime); },
45 window.cancelAnimationFrame = clearTimeout;
46 window['requestAnimationFrame'] = window.requestAnimationFrame;
47 window['cancelAnimationFrame'] = window.cancelAnimationFrame;