-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraf_invalidation.html
134 lines (112 loc) · 5.36 KB
/
raf_invalidation.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<!-- saved from url=(0070)http://vmiura.github.io/chromium-pages/redraw/raf-redraws-stripes.html -->
<html lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<style type="text/css">
html, body {
height: 100%;
overflow: hidden;
background-color: red;
}
#fps {
position: absolute;
bottom: 0;
right: 0;
z-index: 1;
}
#container {
position:absolute;
background-color:magenta;
}
.green-strip {
width: 100%;
height: 30px;
background-color:green;
}
.blue-strip {
width: 100%;
height: 30px;
background-color:blue;
}
</style>
</head>
<body>
<div id="container" style="width: 1260px; height: 1196px; top: 15px; left: 15px;"><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div><div class="blue-strip"></div><div class="green-strip"></div></div>
<div id="fps">57 rAF calls / second</div>
<script type="text/javascript">
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var count = 0,
time = Date.now(),
show_fps = true,
dir = 1,
pos = 0,
container = document.getElementById('container'),
fps = document.getElementById('fps');
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function loop() {
requestAnimationFrame(function() {
if (!document.hidden)
update();
loop();
});
}
function update() {
deltaTime = Date.now() - time;
count++;
pos += dir;
if (pos == 30)
dir = -1;
else if (pos == 0)
dir = 1;
container.style.top = pos + 'px';
container.style.left = pos + 'px';
if (show_fps && deltaTime >= 1000) {
fps.textContent = Math.round(((count / deltaTime) * 1000)) + ' rAF calls / second';
count = 0;
time = Date.now();
}
}
window.onload = function() {
fps_param = getParameterByName('f');
var width_percentage = getParameterByName('w') || 100;
var height_percentage = getParameterByName('h') || 100;
var text = getParameterByName('t') || false;
if (fps_param)
show_fps = (fps_param != '0')
if (!show_fps)
document.body.removeChild(fps);
var clientWidth = document.documentElement.clientWidth;
var clientHeight = document.documentElement.clientHeight;
var containerWidth = clientWidth * (width_percentage / 100) - 50;
var containerHeight = clientHeight * (height_percentage / 100) - 50;
container.style.width = containerWidth + 'px';
container.style.height = containerHeight + 'px';
var stripHeight = 30;
for (var i = 0; i < Math.ceil(containerHeight / stripHeight); i++) {
var div = document.createElement('div');
if (i % 2) {
div.classList.add('green-strip');
if (text)
div.innerHTML = 'GreenGreenGreenGreenGreenGreenGreenGreenGreenGreenGreenGreen ' + i;
} else {
div.classList.add('blue-strip');
if (text)
div.innerHTML = 'BlueBlueBlueBlueBlueBlueBlueBlueBlueBlueBlueBlueBlueBlue ' + i;
}
container.appendChild(div);
}
loop();
}
</script>
</body></html>