-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimate.html
83 lines (82 loc) · 2.07 KB
/
Animate.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
#container {
width: 400px;
height: 400px;
background-color: darkcyan;
position: relative;
}
#animate1 {
width: 50px;
height: 50px;
background-color: red;
position: absolute;
}
#animate2 {
right: 0;
width: 50px;
height: 50px;
background-color: red;
position: absolute;
}
#animate3 {
bottom: 0;
right: 0;
width: 50px;
height: 50px;
background-color: red;
position: absolute;
}
#animate4 {
bottom: 0;
left: 0;
width: 50px;
height: 50px;
background-color: red;
position: absolute;
}
</style>
</head>
<body>
<p><button onclick="myMove()">Animate Now</button></p>
<div id="container">
<div id="animate1"></div>
<div id="animate2"></div>
<div id="animate3"></div>
<div id="animate4"></div>
</div>
<!-- JavaScript -->
<script>
function myMove() {
let id = null;
const elem1 = document.getElementById("animate1");
const elem2 = document.getElementById("animate2");
const elem3 = document.getElementById("animate3");
const elem4 = document.getElementById("animate4");
let pos = 0;
clearInterval(id);
id = setInterval(frame, 5);
function frame() {
if (pos === 350) {
clearInterval(id);
} else {
pos++;
elem1.style.top = pos + "px";
elem1.style.left = pos + "px";
elem2.style.top = pos + "px";
elem2.style.right = pos + "px";
elem3.style.bottom = pos + "px";
elem3.style.right = pos + "px";
elem4.style.bottom = pos + "px";
elem4.style.left = pos + "px";
}
}
}
</script>
</body>
</html>