Skip to content

Commit a41bba7

Browse files
Merge pull request #50 from AzharAli-github/main
DOM-Animation
2 parents 6d49bd2 + 3fd3dc5 commit a41bba7

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.container {
2+
width: 400px;
3+
height: 400px;
4+
position: relative;
5+
background: yellow;
6+
}
7+
8+
.animate {
9+
width: 50px;
10+
height: 50px;
11+
position: absolute;
12+
background: red;
13+
}
14+
15+
button {
16+
margin-bottom: 20px;
17+
}
18+
19+
h2 {
20+
font-family: monospace;
21+
}
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>DOM-Animation</title>
9+
<link rel="shortcut icon" href="images/js-logo.png" type="image/x-icon">
10+
<link rel="stylesheet" href="css/style.css">
11+
</head>
12+
13+
<body>
14+
<h1>DOM Animation</h1>
15+
<h2>Example</h2>
16+
<button onclick="Move()">Click Me</button>
17+
<div class="container">
18+
<div class="animate">
19+
<p>Hello</p>
20+
</div>
21+
</div>
22+
<script src="script.js"></script>
23+
</body>
24+
25+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function Move() {
2+
let id = null;
3+
const elem = document.querySelector('.animate');
4+
let pos = 0;
5+
clearInterval(id);
6+
id = setInterval(frame, 5);
7+
8+
function frame() {
9+
if (pos == 350) {
10+
clearInterval(id);
11+
} else {
12+
pos++;
13+
elem.style.top = pos + "px";
14+
elem.style.left = pos + "px";
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)