* Handle scroll events with debouncing
()
| 22 | * Handle scroll events with debouncing |
| 23 | */ |
| 24 | function handleScroll() { |
| 25 | if (scrollTimer) { |
| 26 | clearTimeout(scrollTimer); |
| 27 | } |
| 28 | |
| 29 | scrollTimer = setTimeout(() => { |
| 30 | const currentScrollTop = window.pageYOffset || document.documentElement.scrollTop; |
| 31 | |
| 32 | // Determine scroll direction and position |
| 33 | const isScrollingDown = currentScrollTop > lastScrollTop; |
| 34 | const hasScrolledPastThreshold = currentScrollTop > SCROLL_THRESHOLD; |
| 35 | |
| 36 | // Add or remove scrolled class based on scroll position and direction |
| 37 | if (hasScrolledPastThreshold && isScrollingDown) { |
| 38 | header.classList.add('md-header--scrolled'); |
| 39 | } else if (currentScrollTop <= SCROLL_THRESHOLD) { |
| 40 | header.classList.remove('md-header--scrolled'); |
| 41 | } |
| 42 | |
| 43 | lastScrollTop = currentScrollTop; |
| 44 | }, SCROLL_DEBOUNCE); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Initialize scroll behavior |
no test coverage detected