Skip to content

DOM-Animation #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions JavaScript/Advance/DOM/7. DOM Animation/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.container {
width: 400px;
height: 400px;
position: relative;
background: yellow;
}

.animate {
width: 50px;
height: 50px;
position: absolute;
background: red;
}

button {
margin-bottom: 20px;
}

h2 {
font-family: monospace;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions JavaScript/Advance/DOM/7. DOM Animation/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM-Animation</title>
<link rel="shortcut icon" href="images/js-logo.png" type="image/x-icon">
<link rel="stylesheet" href="css/style.css">
</head>

<body>
<h1>DOM Animation</h1>
<h2>Example</h2>
<button onclick="Move()">Click Me</button>
<div class="container">
<div class="animate">
<p>Hello</p>
</div>
</div>
<script src="script.js"></script>
</body>

</html>
17 changes: 17 additions & 0 deletions JavaScript/Advance/DOM/7. DOM Animation/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function Move() {
let id = null;
const elem = document.querySelector('.animate');
let pos = 0;
clearInterval(id);
id = setInterval(frame, 5);

function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + "px";
elem.style.left = pos + "px";
}
}
}