Open vignesh1507 opened 5 days ago
import { useEffect, useState } from "react"; import Image from "next/image"; const Navbar = () => { const [visible, setVisible] = useState(false); // Start hidden const [scrollPosition, setScrollPosition] = useState(0); useEffect(() => { const handleScroll = () => { const currentScrollPos = window.scrollY; // Show when scrolling up, hide when scrolling down if (currentScrollPos < scrollPosition) { setVisible(true); // Scrolling up, show navbar } else if (currentScrollPos > scrollPosition) { setVisible(false); // Scrolling down, hide navbar } setScrollPosition(currentScrollPos); }; window.addEventListener("scroll", handleScroll); return () => { window.removeEventListener("scroll", handleScroll); }; }, [scrollPosition]); return ( <nav className={`fixed w-full z-20 top-0 transition-transform duration-300 ease-in-out ${ visible ? "transform translate-y-0" : "transform -translate-y-full" }`} > <div className="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4"> <a href="#" className="flex items-center space-x-3"> <Image src="https://flowbite.com/docs/images/logo.svg" alt="Flowbite Logo" width={32} height={32} /> <span className="self-center text-2xl font-semibold whitespace-nowrap dark:text-white"> Flowbite </span> </a> <div className="flex md:order-2 space-x-3"> <button type="button" className="text-white hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" > Get started </button> </div> <div className="items-center justify-between hidden w-full md:flex md:w-auto md:order-1" id="navbar-sticky" > <ul className="flex flex-col p-4 md:p-0 mt-4 font-medium md:space-x-8 md:flex-row"> <li> <a href="#" className="block py-2 px-3 text-white rounded md:bg-transparent md:text-blue-700 md:p-0" aria-current="page" > Home </a> </li> <li> <a href="#" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:hover:text-blue-700 md:p-0" > About </a> </li> <li> <a href="#" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:hover:text-blue-700 md:p-0" > Services </a> </li> <li> <a href="#" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:hover:text-blue-700 md:p-0" > Contact </a> </li> </ul> </div> </div> </nav> ); }; export default Navbar;
kindly follow the pr checklist
8 Resolved.