Implement scroll animations across multiple sections in HTML files. Update CSS to define animation styles and visibility transitions for elements with the class "animate-on-scroll".
This commit is contained in:
1 parent
535600ab5c
commit
2aea656f0b
13 files changed
+201
-152
No files matched your search
@@ -167,3 +167,21 @@ document.querySelectorAll(".nav").forEach((nav) => {
|
||||
if (!event.matches) setMenuState(false);
|
||||
});
|
||||
});
|
||||
|
||||
// Scroll Animations
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const observerOptions = { root: null, rootMargin: "0px", threshold: 0.4 };
|
||||
const onIntersection = (entries, observer) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
entry.target.classList.add("visible");
|
||||
observer.unobserve(entry.target);
|
||||
}
|
||||
});
|
||||
};
|
||||
const observer = new IntersectionObserver(onIntersection, observerOptions);
|
||||
const elementsToAnimate = document.querySelectorAll(
|
||||
".animate-on-scroll",
|
||||
);
|
||||
elementsToAnimate.forEach((el) => observer.observe(el));
|
||||
});
|
||||
Reference in new issue
Block a user