ycyc
This commit is contained in:
@@ -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;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user