Skip to content

Commit 80fd7c2

Browse files
committed
add scroll animation
1 parent ce34b0b commit 80fd7c2

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

06-scroll animation/index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="style.css" />
7+
<title>Scroll Animation</title>
8+
</head>
9+
<body>
10+
<h1>Scroll to see the animation</h1>
11+
<div class="box"><h2>Content</h2></div>
12+
<div class="box"><h2>Content</h2></div>
13+
<div class="box"><h2>Content</h2></div>
14+
<div class="box"><h2>Content</h2></div>
15+
<div class="box"><h2>Content</h2></div>
16+
<div class="box"><h2>Content</h2></div>
17+
<div class="box"><h2>Content</h2></div>
18+
<div class="box"><h2>Content</h2></div>
19+
<div class="box"><h2>Content</h2></div>
20+
<div class="box"><h2>Content</h2></div>
21+
<div class="box"><h2>Content</h2></div>
22+
<div class="box"><h2>Content</h2></div>
23+
<script src="script.js"></script>
24+
</body>
25+
</html>

06-scroll animation/script.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const boxes = document.querySelectorAll(".box");
2+
3+
const checkBoxes = () => {
4+
const triggerBottom = (window.innerHeight / 5) * 4;
5+
boxes.forEach((box) => {
6+
const boxTop = box.getBoundingClientRect().top;
7+
if (boxTop < triggerBottom) box.classList.add("show");
8+
else box.classList.remove("show");
9+
});
10+
};
11+
12+
window.addEventListener("scroll", checkBoxes);
13+
checkBoxes();

06-scroll animation/style.css

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap");
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: #efedd6;
9+
font-family: "Roboto", sans-serif;
10+
display: flex;
11+
flex-direction: column;
12+
align-items: center;
13+
justify-content: center;
14+
margin: 0;
15+
overflow-x: hidden;
16+
}
17+
18+
h1 {
19+
margin: 10px;
20+
}
21+
22+
.box {
23+
background-color: #867893;
24+
color: #fff;
25+
display: flex;
26+
align-items: center;
27+
justify-content: center;
28+
width: 400px;
29+
height: 200px;
30+
margin: 10px;
31+
border-radius: 10px;
32+
box-shadow: 2px 4px 5px rgba(0, 0, 0, 0.3);
33+
transform: translateX(400%);
34+
transition: transform 0.4s ease;
35+
}
36+
37+
.box:nth-of-type(even) {
38+
transform: translateX(-400%);
39+
}
40+
41+
.box.show {
42+
transform: translateX(0);
43+
}
44+
45+
.box h2 {
46+
font-size: 45px;
47+
}

0 commit comments

Comments
 (0)