-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
38 lines (30 loc) · 1.17 KB
/
main.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
34
35
36
37
38
(function(global, define){
'use strict';
define(function(require){
var now = require('./now');
var lastTime = 0;
var vendors = ['moz', 'webkit'];
for(var x = 0; x < vendors.length && !global.requestAnimationFrame; ++x) {
global.requestAnimationFrame = global[vendors[x]+'RequestAnimationFrame'];
global.cancelAnimationFrame = global[vendors[x]+'CancelAnimationFrame'] || global[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!global.requestAnimationFrame){
global.requestAnimationFrame = function(callback) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = global.setTimeout(function() { callback(now()); }, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}
if (!global.cancelAnimationFrame){
global.cancelAnimationFrame = function(id) {
global.clearTimeout(id);
};
}
});
}(
typeof global == 'object' ? global : this.window || this.global,
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
// Boilerplate for AMD and Node
));