trihub-ernaehrung-advinters/script.js

52 lines
1.6 KiB
JavaScript

// ----- Mobile Navigation -----
(function () {
const toggle = document.querySelector(".nav-toggle");
const nav = document.getElementById("main-nav");
if (!toggle || !nav) return;
toggle.addEventListener("click", function () {
const open = nav.classList.toggle("open");
toggle.setAttribute("aria-expanded", String(open));
toggle.setAttribute("aria-label", open ? "Menü schließen" : "Menü öffnen");
});
// Menü nach Klick auf einen Link automatisch schließen
nav.querySelectorAll("a").forEach(function (link) {
link.addEventListener("click", function () {
nav.classList.remove("open");
toggle.setAttribute("aria-expanded", "false");
});
});
})();
// ----- Scroll-Reveal -----
(function () {
const elements = document.querySelectorAll(".reveal");
if (!elements.length) return;
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (reduceMotion || !("IntersectionObserver" in window)) {
elements.forEach(function (el) {
el.classList.add("visible");
});
return;
}
const observer = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.12, rootMargin: "0px 0px -40px 0px" }
);
elements.forEach(function (el) {
observer.observe(el);
});
})();