Skip to content

Commit

Permalink
remove smooth scroll, add basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushYadlapati committed Aug 16, 2024
1 parent 9eb1e63 commit 9983564
Showing 1 changed file with 9 additions and 45 deletions.
54 changes: 9 additions & 45 deletions app/components/navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use client';

// @flow strict
import Link from "next/link";
import { useEffect } from "react";
import { useRouter } from 'next/navigation';

function Navbar() {
const router = useRouter();

useEffect(() => {
const handleSmoothScroll = (e) => {
e.preventDefault();
const href = e.currentTarget.getAttribute('href');
const targetId = href.replace(/.*\#/, "");

if (targetId) {
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({ behavior: "smooth" });
window.history.pushState({}, '', href);
}
}
};

const links = document.querySelectorAll('a[href^="/#"]');
links.forEach(link => {
link.addEventListener("click", handleSmoothScroll);
});

return () => {
links.forEach(link => {
link.removeEventListener("click", handleSmoothScroll);
});
};
}, []);

function Navbar() {
return (
<nav className="bg-transparent">
<div className="flex items-center justify-between py-5">
<div className="flex flex-shrink-0 items-center">
<Link href="./" className="text-[#16f2b3] text-3xl font-bold">
<Link
href="/"
className=" text-[#16f2b3] text-3xl font-bold">
arushyadlapati.com
</Link>
</div>
Expand All @@ -51,24 +21,18 @@ function Navbar() {
</Link>
</li>
<li>
<Link className="block px-4 py-2 no-underline outline-none hover:no-underline" href="/#experience">
<div className="text-sm text-white transition-colors duration-300 hover:text-pink-600">EXPERIENCE</div>
</Link>
<Link className="block px-4 py-2 no-underline outline-none hover:no-underline" href="/#experience"><div className="text-sm text-white transition-colors duration-300 hover:text-pink-600">EXPERIENCE</div></Link>
</li>
<li>
<Link className="block px-4 py-2 no-underline outline-none hover:no-underline" href="/#skills">
<div className="text-sm text-white transition-colors duration-300 hover:text-pink-600">SKILLS</div>
</Link>
<Link className="block px-4 py-2 no-underline outline-none hover:no-underline" href="/#skills"><div className="text-sm text-white transition-colors duration-300 hover:text-pink-600">SKILLS</div></Link>
</li>
<li>
<Link className="block px-4 py-2 no-underline outline-none hover:no-underline" href="/#projects">
<div className="text-sm text-white transition-colors duration-300 hover:text-pink-600">PROJECTS</div>
</Link>
<Link className="block px-4 py-2 no-underline outline-none hover:no-underline" href="/#projects"><div className="text-sm text-white transition-colors duration-300 hover:text-pink-600">PROJECTS</div></Link>
</li>
</ul>
</div>
</nav>
);
}
};

export default Navbar;
export default Navbar;

0 comments on commit 9983564

Please sign in to comment.