Skip to content

Commit 13a32fb

Browse files
lwinmoepaingclaude
andcommitted
💄 style: add hide-on-scroll-down sticky navbar
Switch navbar from sticky to fixed positioning with hide/reveal animation. Navbar hides when scrolling down past 80px, reveals on scroll up with smooth spring transition. Added pt-16 to main content to offset fixed navbar height. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 59759f3 commit 13a32fb

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default async function RootLayout({
5656
<LanguageProvider>
5757
<div className="noise-overlay" />
5858
<Navbar />
59-
<main className="min-h-[calc(100vh-142px)]">{children}</main>
59+
<main className="min-h-[calc(100vh-142px)] pt-16">{children}</main>
6060
<Footer />
6161
</LanguageProvider>
6262
</NextIntlClientProvider>

src/components/Common/Navbar/Navbar.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,26 @@ const Navbar = () => {
287287
const path = usePathname();
288288
const [mobileOpen, setMobileOpen] = useState(false);
289289
const [scrolled, setScrolled] = useState(false);
290+
const [hidden, setHidden] = useState(false);
291+
const lastScrollY = useRef(0);
290292
const t = useTranslations("nav");
291293
const { isMyanmar } = useLanguage();
292294
const mmFont = isMyanmar ? khitHaungg.className : "";
293295

294296
const closeMobile = useCallback(() => setMobileOpen(false), []);
295297

296298
useEffect(() => {
297-
const onScroll = () => setScrolled(window.scrollY > 20);
299+
const onScroll = () => {
300+
const currentY = window.scrollY;
301+
setScrolled(currentY > 20);
302+
// Hide navbar when scrolling down past 80px, show when scrolling up
303+
if (currentY > 80 && currentY > lastScrollY.current) {
304+
setHidden(true);
305+
} else {
306+
setHidden(false);
307+
}
308+
lastScrollY.current = currentY;
309+
};
298310
window.addEventListener("scroll", onScroll, { passive: true });
299311
return () => window.removeEventListener("scroll", onScroll);
300312
}, []);
@@ -308,11 +320,11 @@ const Navbar = () => {
308320
return (
309321
<>
310322
<motion.nav
311-
initial={{ y: -80, opacity: 0 }}
312-
animate={{ y: 0, opacity: 1 }}
313-
transition={{ duration: 0.7, ease: [0.22, 1, 0.36, 1] }}
323+
initial={{ y: -80 }}
324+
animate={{ y: hidden && !mobileOpen ? -80 : 0 }}
325+
transition={{ duration: 0.35, ease: [0.22, 1, 0.36, 1] }}
314326
className={cn(
315-
"sticky top-0 z-40 w-full transition-all duration-500",
327+
"fixed top-0 left-0 right-0 z-40 w-full transition-[background,box-shadow] duration-500",
316328
scrolled
317329
? "bg-obsidian/90 backdrop-blur-2xl shadow-[0_4px_30px_rgba(0,0,0,0.5)]"
318330
: "bg-obsidian/60 backdrop-blur-xl"

0 commit comments

Comments
 (0)