-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
33 lines (26 loc) · 966 Bytes
/
main.js
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
// Load-Animation
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("appear");
} else {
entry.target.classList.remove("appear");
}
});
});
const hiddenElements = document.querySelectorAll(".hidden");
hiddenElements.forEach((el) => observer.observe(el));
// Scroll Animation
const scrollAnimationElements = document.querySelectorAll(".scroll-animation");
const handleScrollAnimation = () => {
scrollAnimationElements.forEach((el) => {
const rect = el.getBoundingClientRect();
const windowHeight = window.innerHeight;
if (rect.top <= windowHeight / 2 && rect.bottom >= 0) {
el.classList.add("appear");
} else {
el.classList.remove("appear");
}
});
};
window.addEventListener("scroll", handleScrollAnimation);