-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
52 lines (48 loc) · 1.71 KB
/
demo.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
<!doctype html>
<html>
<head>
<title>requestAnimationFrame.js demo</title>
<style type="text/css">
canvas {
display: block;
border: 1px dotted black;
}
</style>
</head>
<body>
<p>This demo shows 5 canvases rendering independent frame counters through requestAnimationFrame API.<br/>
TODO: You can check that elements not within the viewport are not rendered unnecessarily by checking their counters.</p>
<canvas id="canvas-1" width="256" height="256"></canvas>
<canvas id="canvas-2" width="256" height="256"></canvas>
<canvas id="canvas-3" width="256" height="256"></canvas>
<canvas id="canvas-4" width="256" height="256"></canvas>
<canvas id="canvas-5" width="256" height="256"></canvas>
<canvas id="canvas-6" width="256" height="256"></canvas>
<canvas id="canvas-7" width="256" height="256"></canvas>
<canvas id="canvas-8" width="256" height="256"></canvas>
<script type="text/javascript">
// using "force" so that it overrides the browser's requestAnimationFrame
// of course this only makes sense here because it's a demo of the shim itself!
window.requestAnimationFrameJS = "force";
</script>
<script type="text/javascript" src="requestAnimationFrame.js"></script>
<script type="text/javascript">
function render() {
var canvas = this;
var ctx = canvas.getContext("2d");
requestAnimationFrame(render, canvas);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "black";
ctx.font = "60px monospace";
ctx.fillText(canvas._count++, 20, 128);
}
// setup rendering loop for each canvas
var elements = document.getElementsByTagName("canvas");
var i;
for (i = 0; i < elements.length; ++i) {
elements[i]._count = 0;
requestAnimationFrame(render, elements[i]);
}
</script>
</body>
</html>