r/reactjs • • Sep 21 '26

Needs Help Frames visible between header versions on scroll

Hi folks I'm trying to display two different headers dependent on scroll, which is working but if i scroll slowly i can see the frames between animations. It's not swapping them instantly.

I'm just conditionally rendering on a Boolean held in state.

I tried doing it via a conditional on display property on each header but still the same issue.

EDIT...both header are using sticky, when i change to fixed i don't get the visible frames but it ruins my layout.

useEffect(() => {
  const onScroll = () => setIsScrolling(window.scrollY > 80);


  window.addEventListener('scroll', onScroll)
  return () => window.removeEventListener("scroll", onScroll);


}, [])

{isScrolling ? <header> full content </header> :<header> scroll content </header>
2 Upvotes

9 comments sorted by

View all comments

0

u/Any_Welder_9701 Sep 21 '26

do the two headers have different heights? swapping sticky elements can change scrollY enough to cross 80px again. id keep one sticky wrapper and only swap the content inside it