-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated the navbar.jsx code file and updated few typos in the README.md file. #10
Open
vignesh1507
wants to merge
4
commits into
GDG-OnCampus-BU:main
Choose a base branch
from
vignesh1507:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Explanation of Changes: Initial State: The navbar is hidden by default (visible = false). Scrolling Logic: When the user scrolls up, the navbar becomes visible; when they scroll down, it hides. Smooth Transition: The transition-transform ensures smooth appearing/disappearing of the navbar.
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; #8 Resolved. |
kindly follow the pr checklist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.