-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
99 lines (80 loc) · 3.01 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Thanks for following
* requestAnimationFrame polyfill by Erik Möller & Paul Irish et. al.
* https://gist.github.com/1866474
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
* http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
**/
/**
* (c) 2015 Alfred UC
* raf-uc may be freely distributed under the MIT license.
* For all details and documentation:
* https://github.com/b6pzeusbc54tvhw5jgpyw8pwz2x6gs/raf-uc
**/
/*jshint asi: false, browser: true, curly: true, eqeqeq: true, forin: false, newcap: true, noempty: true, strict: true, undef: true */
(function( factory ) {
'use strict';
// We use `self` instead of `window` for `WebWorker` support.
var root = (typeof self == 'object' && self.self == self && self) ||
(typeof global == 'object' && global.global == global && global);
// Set up raf-uc appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['exports'], function(exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global rafUC.
root.rafUC = factory( root, exports );
});
// Next for CommonJS.
} else if (typeof exports !== 'undefined') {
factory( root, exports );
// Finally, as a browser global.
} else {
root.rafUC = factory( root, {} );
}
}( function( root, exports ) {
'use strict';
var previousRafUC = root.rafUC;
exports.noConflict = function() {
root.rafUC = previousRafUC;
return this;
};
// cannot be golbal
// var lastTime = 0;
var prefixList = 'webkit moz ms o'.split(' ');
// get unprefixed rAF and cAF, if present
var requestAnimationFrame = root.requestAnimationFrame;
var cancelAnimationFrame = root.cancelAnimationFrame;
// loop through vendor prefixList and get prefixed rAF and cAF
var prefix;
for( var i = 0; i < prefixList.length; i++ ) {
if ( requestAnimationFrame && cancelAnimationFrame ) {
break;
}
prefix = prefixList[i];
requestAnimationFrame = requestAnimationFrame || root[ prefix + 'RequestAnimationFrame' ];
cancelAnimationFrame = cancelAnimationFrame || root[ prefix + 'CancelAnimationFrame' ] ||
root[ prefix + 'CancelRequestAnimationFrame' ];
}
// fallback to setTimeout and clearTimeout if either request/cancel is not supported
if ( !requestAnimationFrame || !cancelAnimationFrame ) {
requestAnimationFrame = function( callback ) {
var lastTime = callback.lastTime || 0
var currTime = new Date().getTime();
var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
var id = root.setTimeout( function() {
callback( currTime + timeToCall );
}, timeToCall );
callback.lastTime = currTime + timeToCall;
return id;
};
cancelAnimationFrame = function( id ) {
root.clearTimeout( id );
};
}
// put in global namespace
root.requestAnimationFrame = requestAnimationFrame;
root.cancelAnimationFrame = cancelAnimationFrame;
exports.raf = requestAnimationFrame;
exports.caf = cancelAnimationFrame;
return exports;
}));