-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
87 lines (65 loc) · 1.65 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>rafPolyfill</title>
<script src="rafPolyfill.js"></script>
<!-- https://codepen.io/chriscoyier/pen/ltseg -->
<style>
div {
width: 10px;
height: 10px;
background: orange;
float: left;
}
button {
position: absolute;
top: 20px;
left: 20px;
}
#stop {
left: 100px;
}
</style>
</head>
<body>
<button id="start">start</button>
<button id="stop">stop</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
;(function(w,d,$){
$(d).ready(function($){
var globalID, body = d.body || d.getElementsByTagName('body')[0], raf = requestAnimationFrame, cancelRaf = cancelAnimationFrame;
function repeatOften() { //return false;
body.appendChild(d.createElement('div'));
globalID = raf(repeatOften);
}
//globalID = raf(repeatOften);
$("#stop").on("click", function(){
cancelRaf(globalID);
});
$("#start").on("click", function() {
globalID = raf(repeatOften);
});
$("#start").trigger('click');
//setTimeout(function(){$("#stop").trigger("click")},2000);
setTimeout(function(){
raf(function(){ console.log('Check callback queued') });
},2000);
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){});
raf(function(){ $('body').css('background-color', 'green') });
});
})(window, document, jQuery);
</script>
</body>
</html>