From b6ce5d7a795f16ce73f54e1a2416ededc789d008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Thu, 11 Jun 2026 23:25:59 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20transitions.js=20=E2=80=93=20Seiten?= =?UTF-8?q?=C3=BCbergang,=20Scroll-Einblenden,=20Dock-Active-State?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/custom/transitions.js | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 public/custom/transitions.js diff --git a/public/custom/transitions.js b/public/custom/transitions.js new file mode 100644 index 0000000..454cf1c --- /dev/null +++ b/public/custom/transitions.js @@ -0,0 +1,108 @@ +/* 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 ---------- */ + var pfad = 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(); + } +})();