-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
40 lines (32 loc) · 960 Bytes
/
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Creating animations inside a canvas</title>
</head>
<body>
<canvas id="my_canvas"
width="300" height="300"
style="border:solid 1px">
</canvas>
<script>
(function() {
var myCanvas =
document.getElementById("my_canvas");
var context = myCanvas.getContext("2d");
var initialX=20;
var finalX=220;
var currentX=initialX;
function draw() {
context.clearRect(0,0,300,300);
context.fillRect(currentX,currentX,50,50);
if(currentX<finalX) {
currentX=currentX+1;
}
requestAnimationFrame(draw);
}
draw();
})();
</script>
</body>
</html>