const headerObserver = new IntersectionObserver(obsCallback, { root: null, threshold: 0.01, // Use a tiny threshold instead of 0 rootMargin: `-${navHeight}px 0px 0px 0px`, // Explicitly define margins });