forked from flyover/spriter.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshim.js
34 lines (30 loc) · 947 Bytes
/
shim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// shim: window.requestAnimationFrame window.cancelAnimationFrame
/* scope */ ;(function ()
{
var vendors = ['ms', 'Moz', 'Webkit', 'O'];
for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i)
{
window.requestAnimationFrame = window[vendors[i]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame'] || window[vendors[i]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
{
var lastTime = 0;
window.requestAnimationFrame = function (callback, element)
{
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function () { callback(currTime + timeToCall); }, timeToCall);
lastTime = currTime + timeToCall;
return id;
}
}
if (!window.cancelAnimationFrame)
{
window.cancelAnimationFrame = function (id)
{
window.clearTimeout(id);
}
}
}
/* scope */ )();