This commit is contained in:
2025-12-28 23:53:33 +01:00
parent 7a3089668f
commit 51872e9a69
3 changed files with 189 additions and 3 deletions

View File

@@ -15,14 +15,23 @@ document.addEventListener('DOMContentLoaded', () => {
img.src = `/assets/bilder/${chosenLogo}`;
});
// Header shrink on scroll
// Header shrink on scroll with hysteresis to avoid flicker
let ticking = false;
let isShrunk = false;
const SHRINK_ON = 140;
const SHRINK_OFF = 90;
const onScroll = () => {
if (ticking || !header) return;
ticking = true;
window.requestAnimationFrame(() => {
const shouldShrink = window.scrollY > 120;
header.classList.toggle('is-scrolled', shouldShrink);
const y = window.scrollY;
if (!isShrunk && y > SHRINK_ON) {
isShrunk = true;
header.classList.add('is-scrolled');
} else if (isShrunk && y < SHRINK_OFF) {
isShrunk = false;
header.classList.remove('is-scrolled');
}
ticking = false;
});
};