forked from shrey7070/Project01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation2.html
95 lines (94 loc) · 2 KB
/
animation2.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
<!DOCTYPE html>
<html>
<head>
<style>
#container {
margin-left: 50px;
width: 400px;
height: 400px;
position: relative;
background: red;
}
#animate {
width: 50px;
height: 50px;
position: absolute;
background-color: blue;
}
#animat {
width: 50px;
height: 50px;
position: absolute;
background-color: green;
margin-left: 350px;
}
#DP{
margin-left: 800px;
font-size: 100px;
color: red;
}
.button1{
margin-left: 225px;
font-size: 15px;
padding: 10px;
color: white;
background-color: black;
border: none;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<h2 align="center">Animation Time</h2>
<p>
<button class="button1" onclick="myMove()">Click Me</button>
</p>
<div id ="container">
<div id ="animate"></div>
<div id ="animat"></div>
<div id ="DP">
DP
</div>
</div>
<script>
function myMove() {
var elem = document.getElementById("animate");
var elem1 = document.getElementById("animat");
var elem2 = document.getElementById("DP");
var pos = 0;
var pos1 = 0;
var pos2 = 0;
var id = setInterval(frame, 15);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + 'px';
elem.style.left = pos + 'px';
}
}
var id1 = setInterval(frame1, 15);
function frame1() {
if (pos1 == 350) {
clearInterval(id1);
} else {
pos1=pos1+1;
elem1.style.top = pos1 + 'px';
elem1.style.right = pos1 + 'px';
}
}
var id2 = setInterval(frame2, 17);
function frame2() {
if (pos2 == 300) {
clearInterval(id2);
} else {
pos2=pos2+1;
elem2.style.paddingTop = pos2 + 'px';
}
}
}
</script>
</body>
</html>