Files
portfolio-photo/public/custom/transitions.js
T
Leon TonhäuserandClaude 3c5abfd87f Merge origin/main: Tiefenflug-Auto-Player konsequent durch Fokus ersetzt
main hat zwischenzeitlich den zeitgesteuerten Tiefenflug-Auto-Player gemergt
(auto-player.js/css, Skip-Button, transitions.js wartet auf html.intro-beendet).
Konflikt-Auflösung zugunsten Fokus:

- tiefenflug.css/js und auto-player.css/js gelöscht (komplettes altes Intro weg).
- index.html: Fokus-Intro + fokus.js-Scripttag behalten, Auto-Player-Scripttag
  und Skip-Button entfernt.
- fokus.js setzt jetzt html.intro-beendet (reduced-motion sofort, scroll-basiert
  am Streckenende), damit transitions.js das Dock wie gewohnt einblendet.
- transitions.js-Kommentar verweist korrekt auf fokus.js.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-23 22:49:49 +02:00

136 lines
5.3 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.
/* 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);
});
/* Zurück-Navigation: der Back-Forward-Cache stellt die Seite im
ausgeblendeten Zustand (seite-ausgang) wieder her → wieder einblenden */
window.addEventListener("pageshow", function (e) {
if (e.persisted) document.body.classList.remove("seite-ausgang");
});
/* ---------- 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.
Vergleich nur über das letzte Pfadsegment – ein Teilstring-Vergleich
würde z. B. am GitLab-Projektpfad /portfolio-photo/ fälschlich matchen. */
var pfad = decodeURIComponent(window.location.pathname);
var seite = pfad.replace(/\/$/, "").split("/").pop()
.replace(/\.html$/, "").replace(/^index$/, "");
var dockLinks = document.querySelectorAll(".dock-links a");
dockLinks.forEach(function (a) {
var hp = a.getAttribute("href") || "";
if (/^(mailto:|tel:|https?:|#)/i.test(hp)) return;
var ziel = hp.replace(/\/$/, "").split("/").pop().replace(/\.html$/, "");
if (ziel && seite === ziel) {
a.setAttribute("aria-current", "page");
}
});
/* ---------- 4b) Dock einblenden beim Scrollen
- ohne Intro (Unterseiten): ab scrollY > 200 sichtbar
- mit Intro (Startseite): ausgeblendet, bis html.intro-beendet gesetzt
ist (siehe fokus.js) – dann sofort sichtbar. ---------- */
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();
} else if (dock && hatIntro) {
var beobachterIntro = new MutationObserver(function () {
if (document.documentElement.classList.contains("intro-beendet")) {
dock.classList.add("sichtbar");
beobachterIntro.disconnect();
}
});
beobachterIntro.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
// Fallback: ist die Klasse schon gesetzt (reduced-motion / Reload am Seitenende)?
if (document.documentElement.classList.contains("intro-beendet")) {
dock.classList.add("sichtbar");
beobachterIntro.disconnect();
}
}
})();