2014-03-27 18:52:07 +01:00
|
|
|
(function () {
|
2014-03-11 14:48:42 +01:00
|
|
|
var lastTime = 0;
|
|
|
|
var vendors = ['webkit', 'moz'];
|
2014-03-27 18:52:07 +01:00
|
|
|
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
|
|
|
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
|
|
|
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
|
|
|
|
window[vendors[x] + 'CancelRequestAnimationFrame'];
|
2014-03-11 14:48:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!window.requestAnimationFrame) {
|
2014-03-27 18:52:07 +01:00
|
|
|
window.requestAnimationFrame = function (callback) {
|
2014-03-11 14:48:42 +01:00
|
|
|
var currTime = new Date().getTime();
|
|
|
|
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
2014-03-27 18:52:07 +01:00
|
|
|
var id = window.setTimeout(function () {
|
|
|
|
callback(currTime + timeToCall);
|
|
|
|
},
|
2014-03-11 14:48:42 +01:00
|
|
|
timeToCall);
|
|
|
|
lastTime = currTime + timeToCall;
|
|
|
|
return id;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!window.cancelAnimationFrame) {
|
2014-03-27 18:52:07 +01:00
|
|
|
window.cancelAnimationFrame = function (id) {
|
2014-03-11 14:48:42 +01:00
|
|
|
clearTimeout(id);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}());
|