let lastScrollPosition = 0; const headerWrapper = document.querySelector('#header-wrapper'); // Changed selector const scrollThreshold = 100; function getTranslateValue() { return window.innerWidth <= 477 ? -38 : -60; } window.addEventListener('scroll', () => { const currentScrollPosition = window.pageYOffset || document.documentElement.scrollTop; if (currentScrollPosition > scrollThreshold) { // Scrolling down if (currentScrollPosition > lastScrollPosition) { headerWrapper.style.transform = `translateY(${getTranslateValue()}px)`; } // Scrolling up else { headerWrapper.style.transform = 'translateY(0)'; } } else { // Reset position when above threshold headerWrapper.style.transform = 'translateY(0)'; } lastScrollPosition = currentScrollPosition; }); // Handle resize events window.addEventListener('resize', () => { if (lastScrollPosition > scrollThreshold) { headerWrapper.style.transform = `translateY(${getTranslateValue()}px)`; } });