MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / handleScroll

Function handleScroll

docs/javascripts/header-scroll.js:24–45  ·  view source on GitHub ↗

* Handle scroll events with debouncing

()

Source from the content-addressed store, hash-verified

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

Callers 1

initScrollBehaviorFunction · 0.85

Calls 2

removeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected