/* zeitlinie.js – Animationen für die Saison-Rückblick-Zeitleiste: 1) Tauch-Fahrt: Einträge starten tief im Raum und kommen beim Scrollen auf den Betrachter zu (an den Scroll gekoppelt, wie eine Kamerafahrt durch den Saison-Speicher) 2) Goldene Fortschritts-Achse beim Scrollen 3) Dezenter 3D-Tilt der Karten bei Mausbewegung (nur Desktop-Zeiger) Mit Motion läuft 1)+2) als Scroll-Scrubbing; ohne Motion gilt das einfache Einblenden-System. Respektiert prefers-reduced-motion. */ (function () { "use strict"; var reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches; var M = window.Motion; var liste = document.querySelector(".zeitliste"); if (!liste) return; var punkte = Array.prototype.slice.call(liste.querySelectorAll(".zeit-punkt")); var mitMotion = !!(M && typeof M.animate === "function" && typeof M.scroll === "function") && !reduce; if (mitMotion) { /* ---------- 1)+2) Kamerafahrt + Achse, beide am Scroll ---------- */ var mobil = window.matchMedia("(max-width: 859.98px)"); var tiefe = function () { return mobil.matches ? 520 : 900; }; function zustand(punkt, f) { /* f = 0: ganz hinten im Raum · f = 1: angekommen */ var rest = 1 - f; punkt.style.opacity = String(Math.min(1, f / 0.4)); punkt.style.transform = "translateZ(" + (-rest * tiefe()).toFixed(1) + "px)" + " rotateX(" + (rest * 6).toFixed(2) + "deg)"; } punkte.forEach(function (punkt) { punkt.style.transition = "none"; punkt.style.willChange = "transform, opacity"; zustand(punkt, 0); }); var fahren = function () { var kante = window.innerHeight; var beginn = kante * 0.97; /* Eintritt unten im Fenster */ var ende = kante * 0.46; /* Ruheposition erreicht */ for (var i = 0; i < punkte.length; i++) { var oben = punkte[i].getBoundingClientRect().top; var f = (beginn - oben) / (beginn - ende); f = Math.min(1, Math.max(0, f)); zustand(punkte[i], f); } var r = liste.getBoundingClientRect(); var achse = (kante * 0.7 - r.top) / r.height; achse = Math.min(1, Math.max(0, achse)); liste.style.setProperty("--fortschritt", (achse * 100).toFixed(2) + "%"); }; fahren(); /* Startzustand sofort herstellen … */ M.scroll(fahren); /* … und danach an den Scroll koppeln */ } else { /* ---------- Fallback: sanftes Einblenden wie bisher ---------- */ if (punkte.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, rootMargin: "0px 0px -40px 0px" }); punkte.forEach(function (el) { beobachter.observe(el); }); } else { punkte.forEach(function (el) { el.classList.add("sichtbar"); }); } if (!reduce) { var wartend = false; var aktualisieren = function () { var r = liste.getBoundingClientRect(); var anteil = (window.innerHeight * 0.7 - r.top) / r.height; anteil = Math.min(1, Math.max(0, anteil)); liste.style.setProperty("--fortschritt", (anteil * 100).toFixed(2) + "%"); }; window.addEventListener("scroll", function () { if (!wartend) { wartend = true; window.requestAnimationFrame(function () { wartend = false; aktualisieren(); }); } }, { passive: true }); window.addEventListener("resize", aktualisieren); aktualisieren(); } } /* ---------- 3) 3D-Tilt bei Mausbewegung ---------- */ if ( !reduce && window.matchMedia("(hover: hover) and (pointer: fine)").matches ) { var maxNeigung = 6; // Grad – bewusst dezent liste.querySelectorAll(".zeit-karte").forEach(function (karte) { karte.addEventListener("pointermove", function (e) { var r = karte.getBoundingClientRect(); var x = (e.clientX - r.left) / r.width - 0.5; var y = (e.clientY - r.top) / r.height - 0.5; karte.style.transform = "rotateX(" + (-y * maxNeigung).toFixed(2) + "deg)" + " rotateY(" + (x * maxNeigung).toFixed(2) + "deg)"; }); karte.addEventListener("pointerleave", function () { karte.style.transform = ""; }); }); } })();