/* transitions.js – geteilte Animationen für alle Seiten: 1) Staub-Fade-Seitenübergang bei internen Links 2) Scroll-Einblenden via IntersectionObserver (.einblenden) 3) Dock-Active-State (aria-current) nach location.pathname 4) Dock-Einblenden beim Scrollen (nur Unterseiten ohne Tiefenflug-Intro) Respektiert prefers-reduced-motion. */ (function () { "use strict"; var reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches; /* ---------- 1) Eingangs-Animation: Body sanft einblenden ---------- */ if (!reduce) { document.body.classList.add("seite-eingang"); requestAnimationFrame(function () { requestAnimationFrame(function () { document.body.style.transition = "opacity 0.4s ease-out, transform 0.4s ease-out, filter 0.4s ease-out"; document.body.classList.remove("seite-eingang"); }); }); } /* ---------- Partikel am Klickpunkt ---------- */ function partikel(x, y) { var farben = ["#c9a227", "#98a2b3"]; var anzahl = 5; for (var i = 0; i < anzahl; i++) { var p = document.createElement("div"); p.className = "uebergang-partikel"; var groesse = 4 + Math.random() * 4; // 4–8px p.style.width = groesse + "px"; p.style.height = groesse + "px"; p.style.left = x + "px"; p.style.top = y + "px"; p.style.background = farben[i % farben.length]; var winkel = Math.random() * Math.PI * 2; var weite = 30 + Math.random() * 40; p.style.setProperty("--dx", Math.cos(winkel) * weite + "px"); p.style.setProperty("--dy", Math.sin(winkel) * weite + "px"); document.body.appendChild(p); setTimeout((function (el) { return function () { el.remove(); }; })(p), 520); } } /* ---------- 2) Seitenübergang bei internen Links ---------- */ function internerLink(a) { if (!a || a.target === "_blank") return false; var href = a.getAttribute("href"); if (!href) return false; if (href.charAt(0) === "#") return false; // Anker if (/^(mailto:|tel:|https?:)/i.test(href)) { // extern nur, wenn andere Domain return a.hostname === window.location.hostname; } return true; // relative interne Links (./, ../, seite) } document.addEventListener("click", function (e) { if (reduce) return; var a = e.target.closest ? e.target.closest("a") : null; if (!a || !internerLink(a)) return; if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return; e.preventDefault(); var ziel = a.href; partikel(e.clientX, e.clientY); document.body.classList.add("seite-ausgang"); setTimeout(function () { window.location.href = ziel; }, 320); }); /* ---------- 3) Scroll-Einblenden ---------- */ var elemente = document.querySelectorAll(".einblenden"); if (elemente.length && "IntersectionObserver" in window && !reduce) { var beobachter = new IntersectionObserver(function (eintraege) { eintraege.forEach(function (eintrag) { if (eintrag.isIntersecting) { eintrag.target.classList.add("sichtbar"); beobachter.unobserve(eintrag.target); } }); }, { threshold: 0.15 }); elemente.forEach(function (el) { beobachter.observe(el); }); } else { elemente.forEach(function (el) { el.classList.add("sichtbar"); }); } /* ---------- 4a) Dock-Active-State ---------- */ /* decodeURIComponent: Umlaut-URLs (über-mich) kommen prozent-kodiert an */ var pfad = decodeURIComponent(window.location.pathname).replace(/\/index\.html$/, "/"); var dockLinks = document.querySelectorAll(".dock-links a"); dockLinks.forEach(function (a) { var hp = a.getAttribute("href") || ""; var norm = hp.replace(/^\.\//, "/").replace(/\/$/, ""); var aktuell = pfad.replace(/\/$/, ""); if (norm && aktuell.indexOf(norm) !== -1 && norm !== "/") { a.setAttribute("aria-current", "page"); } }); /* ---------- 4b) Dock einblenden beim Scrollen (nur ohne Tiefenflug-Intro) ---------- */ var dock = document.getElementById("dock"); var hatIntro = document.querySelector(".flug-strecke"); if (dock && !hatIntro) { var prüfen = function () { if (window.scrollY > 200) dock.classList.add("sichtbar"); else dock.classList.remove("sichtbar"); }; window.addEventListener("scroll", prüfen, { passive: true }); prüfen(); } })();