This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.js
109 lines (95 loc) · 2.51 KB
/
script.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
100
101
102
103
104
105
106
107
108
109
var BOX_WIDTH = 100;
var BOX_SPEED = 10;
var box1;
var box2;
var box3;
var box4;
var animationFrameRequest;
var timeoutForJank;
function setCurrentAnimationBasedOnRadioButtons() {
var form_elements = document.getElementById('form').elements.animate;
var on = form_elements.value;
window.cancelAnimationFrame(animationFrameRequest);
box2.animation.pause();
box3.animation.pause();
box4.firstChild.pause();
switch(on) {
case "raf":
animationFrameRequest = window.requestAnimationFrame(tickBox1);
break;
case "main_css":
box2.animation.play();
break;
case "compositor_css":
box3.animation.play();
break;
case "video":
box4.firstChild.play();
break;
case "ALL":
animationFrameRequest = window.requestAnimationFrame(tickBox1);
box2.animation.play();
box3.animation.play();
box4.firstChild.play();
break;
}
}
function initForm() {
var form = document.getElementById('form');
var animate_controls = form.elements.animate;
console.log(animate_controls);
for (i of animate_controls) {
i.onchange = setCurrentAnimationBasedOnRadioButtons;
}
var jank_checkbox = form.elements.jank;
console.log(jank_checkbox);
jank_checkbox.onchange = function() {
if(jank_checkbox.checked) {
jankItUp();
} else {
window.clearTimeout(timeoutForJank);
}
}
}
function tickBox1() {
animationFrameRequest = window.requestAnimationFrame(tickBox1);
box1.left += BOX_SPEED;
if (box1.left > document.body.clientWidth - BOX_WIDTH) {
box1.left = 0;
}
box1.style.left = box1.left + "px";
}
function jankItUp() {
var start = performance.now();
while (performance.now() < start + 2000) {}
timeoutForJank = window.setTimeout(jankItUp, 4000);
}
var animation;
document.addEventListener("DOMContentLoaded", function(event) {
box1 = document.getElementById("box1");
box2 = document.getElementById("box2");
box3 = document.getElementById("box3");
box4 = document.getElementById("box4");
box1.left = 0;
box2.animation = box2.animate([
{
left: '0px'
}, {
left: (document.body.clientWidth - BOX_WIDTH) + 'px'
}], {
duration: document.body.clientWidth / BOX_SPEED * 16.66,
iterations: Infinity
});
box3.animation = box3.animate([
{
transform: 'translate(0px, 0px)'
},
{
transform: 'translate(' + (document.body.clientWidth - BOX_WIDTH) + 'px, 0px)'
}], {
duration: document.body.clientWidth / BOX_SPEED * 16.66,
iterations: Infinity
});
initForm();
setCurrentAnimationBasedOnRadioButtons();
});