let timeout = null; let lastScrollPosition = 0; let minifiedHeader = false; let showMinifiedHeader = false; let justMinified = false; function headerContainer() { return document.getElementById('header-container'); } function mobile_header() { if (document.getElementById('headerContainerPDA')) { return true; } else { return false; } } function handleScrollChange(scrollPosition) { const bodyTop = document.documentElement.getBoundingClientRect().top; const headerHeight = headerContainer().getBoundingClientRect().height; const headerTop = window.scrollY * -1; const headerBottomVisible = scrollPosition < headerTop + headerHeight - bodyTop; const headerTopVisible = scrollPosition <= headerTop - bodyTop; const scrollUp = scrollPosition < lastScrollPosition && !justMinified; justMinified = !minifiedHeader && !headerBottomVisible; if (!headerBottomVisible && !minifiedHeader) { minifiedHeader = true; } else if (minifiedHeader && headerTopVisible) { minifiedHeader = false; } if (mobile_header()) { showMinifiedHeader = minifiedHeader && scrollUp; } else { showMinifiedHeader = minifiedHeader || justMinified; } updateLastScrollPosition(scrollPosition); updateHeaderClasses(); } function updateLastScrollPosition(scrollPosition) { lastScrollPosition = scrollPosition; } function updateHeaderClasses() { const h = document.getElementById('header'); const p = document.getElementsByClassName('pagination_fixed')[0]; let classes = ['container']; if (isMenuOpen) { classes.push('open', 'done'); } if (minifiedHeader) { classes.push('minified-header'); } if (showMinifiedHeader) { classes.push('show-minified-header'); } if (p) { if (showMinifiedHeader) { addClass(p, 'padding-top-53'); removeClass(p, 'padding-top-5'); } else { addClass(p, 'padding-top-5'); removeClass(p, 'padding-top-53'); } } h.className = classes.join(' '); } window.addEventListener('scroll', function () { if (timeout === null) { timeout = setTimeout(() => { const top = window.pageYOffset ?? document.documentElement.scrollTop; handleScrollChange(top); timeout = null; }, 300) } })