Files
portfolio-photo/public/custom/zeitlinie.js
T
Leon Tonhäuser 1dec02e37a feat: Zeitleiste auf Motion-Federn und Scroll-Kopplung
Karten-Eintritt federt jetzt per Motion (spring) in den Raum,
die goldene Achse läuft weich am Scroll entlang statt gestuft.
Ohne Motion oder bei reduzierter Bewegung greift das bisherige
System (IntersectionObserver bzw. sofort sichtbar).
2026-08-26 00:59:53 +02:00

107 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* zeitlinie.js – Animationen für die Saison-Rückblick-Zeitleiste:
1) Eintritt der Einträge (3D-Schwenk von unten)
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. */
(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") && !reduce;
/* ---------- 1) Einträge einfliegen lassen ---------- */
if (mitMotion) {
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 }
);
});
} 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 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) + "%");
};
if (mitMotion && typeof M.scroll === "function") {
M.scroll(aktualisieren);
} else {
var wartend = false;
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 = "";
});
});
}
})();