Added basic scroll animations
This commit is contained in:
1 parent
76546ba1c6
commit
eb6c251eb9
7 files changed
+79
-29
No files matched your search
@@ -7,3 +7,21 @@ const headerEl = document.querySelector(".header");
|
||||
btnNavEl.addEventListener("click", function () {
|
||||
headerEl.classList.toggle("nav-open");
|
||||
});
|
||||
|
||||
// Scroll Animations
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const observerOptions = { root: null, rootMargin: "0px", threshold: 0.5 };
|
||||
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, .animate-on-scroll-delay"
|
||||
);
|
||||
elementsToAnimate.forEach((el) => observer.observe(el));
|
||||
});
|
||||
Reference in new issue
Block a user