forked from dcloudio/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmui.animationframe.js
72 lines (57 loc) · 1.13 KB
/
mui.animationframe.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
/**
* mui animationFrame
*/
(function($, window) {
var rAF = window.requestAnimationFrame;
var cAF = window.cancelAnimationFrame;
var queues = {};
var animationFrame = {
queue : queue,
queueAfter : queueAfter,
cancel : cancel
};
function animation_id() {
var id;
do {
id = Math.floor(Math.random() * 1E9);
} while (id in queues);
return id;
}
function recursion(callback) {
var qid = animation_id();
(function wrapper() {
callback();
queues[qid] = rAF(function() {
delete queues[qid];
wrapper();
});
})();
return qid;
}
function queue(callback) {
var qid = animation_id();
queues[qid] = rAF(function() {
delete queues[qid];
callback.apply(animationFrame, arguments);
});
return qid;
}
function queueAfter(callback) {
var qid;
qid = queue(function() {
queues[qid] = rAF(function() {
delete queues[qid];
callback.apply(animationFrame, arguments);
});
});
return qid;
}
function cancel(qid) {
if ( qid in queues) {
cAF(queues[qid]);
delete queues[qid];
}
return animationFrame;
}
$.animationFrame = animationFrame;
})(mui, window);