r/reactjs • u/rob8624 • 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
View all comments
1
u/Strict-Simple Sep 22 '26 edited Sep 22 '26
Not what you asked, but you can do this with CSS only (modern scroll driven animation). Something like this (writing from memory, not tested):