Back-to-top-Button: erscheint nach 1,5 Viewporthöhen, Fokus-Management, reduced-motion, 48px-Ziel

Enthält auch User-Upgrade: JSON-LD als @graph mit seitenspezifischen Extra-Knoten

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 23:00:03 +02:00
parent 557fe1c16b
commit 259e209692
6 changed files with 252 additions and 20 deletions

View File

@@ -0,0 +1,40 @@
/* Back-to-top: erscheint nach ~1,5 Viewporthöhen Scrolltiefe.
Sanftes Scrollen kommt aus dem CSS (scroll-behavior + reduced-motion-Kill-Switch);
JS übernimmt Sichtbarkeit und Fokus-Management. Ohne JS bleibt der Button hidden. */
(function () {
'use strict';
var button = document.querySelector('.back-to-top');
var main = document.getElementById('main');
if (!button || !main) {
return;
}
button.hidden = false;
var ticking = false;
function update() {
button.classList.toggle('is-visible', window.scrollY > window.innerHeight * 1.5);
ticking = false;
}
window.addEventListener('scroll', function () {
if (!ticking) {
ticking = true;
window.requestAnimationFrame(update);
}
}, { passive: true });
update();
// Deep-Link-Einstiege (#anker): Sprung passiert teils vor dem Listener-Setup.
window.addEventListener('load', update);
button.addEventListener('click', function (event) {
event.preventDefault();
var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
window.scrollTo({ top: 0, behavior: reduced ? 'auto' : 'smooth' });
// Fokus an den Seitenanfang mitnehmen (Tastatur/Screenreader).
main.focus({ preventScroll: true });
});
})();