Custom scroll bar: gold progress rail on the right instead of the browser scrollbar

- Thin rail that fills with gold while scrolling, click jumps to that position, drag scrolls along
- Hidden when the page fits on the screen, browser scrollbar hidden (stays without JavaScript)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-22 02:26:59 +02:00
parent 342066cbfd
commit 8d7b729744
3 changed files with 117 additions and 0 deletions

View file

@ -5643,3 +5643,46 @@ a.calendar-agenda-entry:hover { text-decoration: none; filter: brightness(1.2);
.sidebar-link { padding: 0.38rem 0.75rem; font-size: 0.9rem; }
.sidebar-link .icon { width: 17px; height: 17px; }
}
/* ---- Eigene Scroll-Leiste (assets/js/scroll-progress.js) ----
Browser-Balken aus, stattdessen eine schmale Schiene rechts, die sich golden fuellt. */
html.has-scroll-progress { scrollbar-width: none; }
html.has-scroll-progress::-webkit-scrollbar { display: none; }
.scroll-progress {
position: fixed;
top: 0.75rem;
right: 4px;
bottom: 0.75rem;
width: 4px;
z-index: 900;
border-radius: 999px;
background: rgba(255, 255, 255, 0.06);
cursor: pointer;
touch-action: none;
transition: width 0.18s ease, background 0.18s ease, opacity 0.25s ease;
}
/* Etwas breitere Trefferflaeche zum Anklicken, ohne die Leiste dicker aussehen zu lassen */
.scroll-progress::before { content: ''; position: absolute; inset: -6px -4px; }
.scroll-progress:hover, .scroll-progress.is-dragging { width: 8px; background: rgba(255, 255, 255, 0.1); }
.scroll-progress.is-hidden { opacity: 0; pointer-events: none; }
.scroll-progress-fill {
position: absolute;
inset: 0;
border-radius: inherit;
background: linear-gradient(180deg, #f7e3a1 0%, var(--gold) 55%, #b8891f 100%);
box-shadow: 0 0 8px rgba(201, 162, 39, 0.55);
transform: scaleY(0);
transform-origin: top;
will-change: transform;
}
/* Unten angekommen: kurz aufleuchten */
.scroll-progress.is-end .scroll-progress-fill { box-shadow: 0 0 12px rgba(247, 227, 161, 0.8); }
@media (max-width: 860px) {
.scroll-progress { width: 3px; right: 2px; }
}
@media print {
.scroll-progress { display: none; }
}

View file

@ -0,0 +1,72 @@
/**
* Eigene Scroll-Leiste statt des Browser-Scrollbalkens: eine schmale Schiene am rechten Rand,
* die sich beim Runterscrollen golden fuellt. Klicken springt an die Stelle, Ziehen scrollt mit.
* Der Browser-Balken ist per CSS ausgeblendet (html.has-scroll-progress) - erst wenn dieses Skript
* laeuft, sonst bliebe ohne JavaScript gar keine Leiste uebrig.
*/
(function () {
'use strict';
var root = document.documentElement;
var rail = document.createElement('div');
rail.className = 'scroll-progress';
rail.setAttribute('aria-hidden', 'true');
rail.innerHTML = '<div class="scroll-progress-fill"></div>';
document.body.appendChild(rail);
root.classList.add('has-scroll-progress');
var fill = rail.firstChild;
var ticking = false;
function maxScroll() {
return Math.max(0, root.scrollHeight - window.innerHeight);
}
function update() {
ticking = false;
var max = maxScroll();
// Passt die Seite ganz auf den Bildschirm, braucht es keine Leiste
rail.classList.toggle('is-hidden', max < 4);
var progress = max > 0 ? Math.min(1, Math.max(0, window.scrollY / max)) : 0;
fill.style.transform = 'scaleY(' + progress + ')';
rail.classList.toggle('is-end', progress > 0.995);
}
function schedule() {
if (!ticking) {
ticking = true;
window.requestAnimationFrame(update);
}
}
window.addEventListener('scroll', schedule, { passive: true });
window.addEventListener('resize', schedule);
// Nachladende Bilder/Inhalte aendern die Seitenhoehe
if (window.ResizeObserver) {
new ResizeObserver(schedule).observe(document.body);
}
update();
// Klicken und Ziehen: Position auf der Schiene -> Stelle auf der Seite
function scrollToPointer(clientY, smooth) {
var rect = rail.getBoundingClientRect();
var ratio = Math.min(1, Math.max(0, (clientY - rect.top) / rect.height));
window.scrollTo({ top: ratio * maxScroll(), behavior: smooth ? 'smooth' : 'auto' });
}
rail.addEventListener('pointerdown', function (event) {
event.preventDefault();
rail.setPointerCapture(event.pointerId);
rail.classList.add('is-dragging');
scrollToPointer(event.clientY, true);
});
rail.addEventListener('pointermove', function (event) {
if (rail.classList.contains('is-dragging')) scrollToPointer(event.clientY, false);
});
function stop(event) {
rail.classList.remove('is-dragging');
if (rail.hasPointerCapture && rail.hasPointerCapture(event.pointerId)) rail.releasePointerCapture(event.pointerId);
}
rail.addEventListener('pointerup', stop);
rail.addEventListener('pointercancel', stop);
})();

View file

@ -7,5 +7,7 @@
<?php else: ?>
</main>
<?php endif; ?>
<?php // Eigene Scroll-Leiste am rechten Rand, fuellt sich beim Scrollen (alle Seiten) ?>
<script src="<?= e(asset_url('/assets/js/scroll-progress.js')) ?>"></script>
</body>
</html>