2022-04-24 21:31:33 +02:00
|
|
|
const navBtn = document.querySelector("#menu-btn");
|
|
|
|
const nav = document.querySelector("nav");
|
|
|
|
const navLinks = document.querySelector(".nav-links");
|
2022-04-01 04:41:12 +02:00
|
|
|
|
2022-04-24 21:31:33 +02:00
|
|
|
navBtn.addEventListener("click", () => {
|
|
|
|
navLinks.classList.add("activated");
|
|
|
|
const isExpanded = JSON.parse(navBtn.getAttribute("aria-expanded"));
|
|
|
|
navBtn.setAttribute("aria-expanded", !isExpanded);
|
|
|
|
!isExpanded && nav.classList.add("active");
|
|
|
|
});
|
2022-04-01 04:41:12 +02:00
|
|
|
|
|
|
|
//INTERSECTION OBSERVER
|
|
|
|
|
2022-04-24 21:31:33 +02:00
|
|
|
const navObs = new IntersectionObserver(
|
|
|
|
(entries) => nav.classList.toggle("active", !entries[0].isIntersecting),
|
|
|
|
{ threshold: 0.85 }
|
|
|
|
);
|
2022-04-01 04:41:12 +02:00
|
|
|
|
2022-04-24 21:31:33 +02:00
|
|
|
navObs.observe(document.querySelector("header"));
|
2022-04-01 04:41:12 +02:00
|
|
|
|
2022-04-24 21:31:33 +02:00
|
|
|
const fadeUpObserver = new IntersectionObserver(
|
|
|
|
(entries) => {
|
|
|
|
entries.forEach((entry) => {
|
|
|
|
if (entry.isIntersecting) {
|
|
|
|
entry.target.classList.add("faded");
|
|
|
|
fadeUpObserver.unobserve(entry.target);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
{
|
|
|
|
rootMargin: "-15%",
|
2022-04-01 04:41:12 +02:00
|
|
|
}
|
2022-04-24 21:31:33 +02:00
|
|
|
);
|
2022-04-01 04:41:12 +02:00
|
|
|
|
2022-04-24 21:31:33 +02:00
|
|
|
document.querySelectorAll(".fade-up").forEach((el) => {
|
|
|
|
fadeUpObserver.observe(el);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelectorAll(".nav-link").forEach((link) => {
|
|
|
|
if (link.href === window.location.href) {
|
|
|
|
link.setAttribute("aria-current", "page");
|
|
|
|
}
|
|
|
|
});
|