From 183f0ff46a6d57773f5239699f38ff3d72cda0b7 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 27 Jul 2024 15:23:31 +0530 Subject: [PATCH] style: navbar --- components/Navbar.jsx | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/components/Navbar.jsx b/components/Navbar.jsx index aeaf362..41ef1b3 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -1,5 +1,7 @@ +"use client"; + import Link from "next/link"; -import React from "react"; +import React, { useEffect, useState } from "react"; import Image from "next/image"; import { ModeToggle } from "./ModeToggle"; import { Button } from "../components/ui/button"; @@ -15,8 +17,32 @@ import { import { AlignJustify } from "lucide-react"; const Navbar = () => { + const [scrolled, setScrolled] = useState(false); + + useEffect(() => { + const handleScroll = () => { + const offset = window.scrollY; + if (offset > 50) { + setScrolled(true); + } else { + setScrolled(false); + } + }; + + window.addEventListener("scroll", handleScroll); + return () => { + window.removeEventListener("scroll", handleScroll); + }; + }, []); + + if (scrolled) console.log("scroll triggered"); + return ( -
+
{/* Logo */}