diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index c0c210c..20769cc 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -1,6 +1,6 @@ import { Link, useNavigate } from 'react-router-dom' import { HiUserCircle } from 'react-icons/hi' -import { Fragment } from 'react' +import { Fragment,useEffect,useState } from 'react' import { Menu, Transition } from '@headlessui/react' import "./nav-style.css" @@ -18,18 +18,42 @@ const Navbar = () => { 'About', 'Contact Us', ] + const [navbar, setNavbar] = useState(false) const navigate = useNavigate() let token = sessionStorage.getItem('token') const page = (item) => { if (item === 'Contact Us') navigate('/contact') else if (item === 'About') navigate('/about-us') } + + + //navbar scroll changeBackground function + const changeBackground = () => { + if (window.scrollY >= 100) { + setNavbar(true) + } + else { + setNavbar(false) + } + } + + useEffect(() => { + changeBackground() + // adding the event when scroll change background + window.addEventListener("scroll", changeBackground) + }) + + + return ( + +