From 6b738550d120c037ccb3e56277d738dab400095c Mon Sep 17 00:00:00 2001 From: Ritesh Thakur Date: Wed, 4 Feb 2026 22:52:09 +0530 Subject: [PATCH] feat: Implement auto-hiding navbar with scroll detection - Add useAutoHidingNavbar hook for scroll behavior detection - Hide navbar after scrolling down 100px, show on scroll up - Always visible when scroll position < 10px - Smooth CSS transform animations (300ms duration) - Fixed positioning with proper z-index - Add scroll-mt-16 to anchored sections for proper offset - Add content padding to prevent navbar overlap - Update both Home and Landing page navbars Closes #440 --- .../HomeComponents/Navbar/Navbar.tsx | 29 +++++++- frontend/src/components/HomePage.tsx | 69 ++++++++++--------- .../LandingComponents/About/About.tsx | 2 +- .../LandingComponents/Contact/Contact.tsx | 2 +- .../components/LandingComponents/FAQ/FAQ.tsx | 2 +- .../HowItWorks/HowItWorks.tsx | 2 +- .../LandingComponents/Navbar/Navbar.tsx | 29 +++++++- frontend/src/components/LandingPage.tsx | 16 +++-- frontend/src/hooks/useAutoHidingNavbar.ts | 32 +++++++++ 9 files changed, 136 insertions(+), 47 deletions(-) create mode 100644 frontend/src/hooks/useAutoHidingNavbar.ts diff --git a/frontend/src/components/HomeComponents/Navbar/Navbar.tsx b/frontend/src/components/HomeComponents/Navbar/Navbar.tsx index 8c3d91ef..b124ce8e 100644 --- a/frontend/src/components/HomeComponents/Navbar/Navbar.tsx +++ b/frontend/src/components/HomeComponents/Navbar/Navbar.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { NavigationMenu, NavigationMenuItem, @@ -17,9 +17,34 @@ export const Navbar = ( } ) => { const [isOpen, setIsOpen] = useState(false); + const [isVisible, setIsVisible] = useState(true); + const [lastScrollY, setLastScrollY] = useState(0); + + useEffect(() => { + const handleScroll = () => { + const currentScrollY = window.scrollY; + + if (currentScrollY < 10) { + setIsVisible(true); + } else if (currentScrollY > lastScrollY && currentScrollY > 100) { + setIsVisible(false); + } else if (currentScrollY < lastScrollY) { + setIsVisible(true); + } + + setLastScrollY(currentScrollY); + }; + + window.addEventListener('scroll', handleScroll, { passive: true }); + return () => window.removeEventListener('scroll', handleScroll); + }, [lastScrollY]); return ( -
+
diff --git a/frontend/src/components/HomePage.tsx b/frontend/src/components/HomePage.tsx index 24eeb8a2..feb5cc03 100644 --- a/frontend/src/components/HomePage.tsx +++ b/frontend/src/components/HomePage.tsx @@ -302,39 +302,42 @@ export const HomePage: React.FC = () => { setIsLoading={setIsLoading} /> - - - -
- -
-
- -
-
- -
-