forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimated-canvas-as-background.html
42 lines (38 loc) · 1.04 KB
/
animated-canvas-as-background.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
<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 300px;
height: 300px;
background-image: -webkit-canvas(sourceCanvas);
background-size: 100%;
display: inline-block;
}
</style>
</head>
<body>
<p>This test passes if two green squares are displayed below.</p>
<div>
<div style="display: inline-block">
<div id="container"></div>
</div>
<div id="canvas-container" style="display: inline-block"></div>
</div>
<script>
var ctx = document.getCSSCanvasContext('2d', 'sourceCanvas', 300, 300);
var canvas = ctx.canvas;
function asyncDraw2() {
ctx.fillStyle = "green";
ctx.fillRect(0, 0, 300, 300);
}
function asyncDraw1() {
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 300, 300);
window.webkitRequestAnimationFrame(asyncDraw2);
}
window.webkitRequestAnimationFrame(asyncDraw1);
document.querySelector('#canvas-container').appendChild(canvas);
</script>
</body>
</html>