diff --git a/public/custom/zeitlinie.js b/public/custom/zeitlinie.js index 9bad7aa..b43e746 100644 --- a/public/custom/zeitlinie.js +++ b/public/custom/zeitlinie.js @@ -1,10 +1,11 @@ /* zeitlinie.js – Animationen für die Saison-Rückblick-Zeitleiste: - 1) Eintritt der Einträge (3D-Schwenk von unten) + 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) Dezenten 3D-Tilt der Karten bei Mausbewegung (nur Desktop-Zeiger) - Mit Motion (bewegung.js-Ladereihe) federn die Einträge und hängt die - Achse direkt am Scroll – ohne Motion gilt das einfache System. - Respektiert prefers-reduced-motion. */ + 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; @@ -12,63 +13,72 @@ 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") && !reduce; + var mitMotion = !!(M && typeof M.animate === "function" && + typeof M.scroll === "function") && !reduce; - /* ---------- 1) Einträge einfliegen lassen ---------- */ 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.opacity = "0"; - punkt.style.transform = - "rotateX(12deg) translateY(46px) scale(0.97)"; - M.inView( - punkt, - function () { - if (punkt.dataset.bewegungFertig) return; - punkt.dataset.bewegungFertig = "1"; - M.animate( - punkt, - { - opacity: [0, 1], - transform: [ - "rotateX(12deg) translateY(46px) scale(0.97)", - "rotateX(0deg) translateY(0px) scale(1)" - ] - }, - { type: "spring", stiffness: 170, damping: 24 } - ); - }, - { amount: 0.18 } - ); + punkt.style.willChange = "transform, opacity"; + zustand(punkt, 0); }); - } else 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"); }); - } - /* ---------- 2) Fortschritt der Achse ---------- - Mit Motion direkt an den Scroll gekoppelt (weich scrubbing), - sonst über einen entprellten Scroll-Handler. */ - if (!reduce) { - var aktualisieren = function () { + 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 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) + "%"); + 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) + "%"); }; - if (mitMotion && typeof M.scroll === "function") { - M.scroll(aktualisieren); + 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;