This is a quick tutorial on how to hide the navbar when scrolling down, and make it reappear when scrolling back up.
This effect is used here in this blog site, so you can see it in action.
To achieve it, we will be using Framer Motion package, so go ahead and install it.
Next, import it in your Navbar component. We will also use useScroll
and useMotionValueEvent
hooks.
We need to update the nav property to use motion. We also set variants that are using normal CSS classes, animate, and transition.
Animate is a boolean that will use the variant based on the value of navHidden variable.
I gave the navbar some simple Tailwind CSS
styling, but feel free to style it as you please.
Add this:
And you're done.