Skip to content

Commit

Permalink
refactor(navbar): ♻️ improve updateNav() structure
Browse files Browse the repository at this point in the history
  • Loading branch information
404-Program-not-found committed Jun 13, 2023
1 parent 3abc803 commit 1c8ecfb
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/components/Head.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,18 @@ function onUnhover() {
}
function updateNav() {
if (!navElement.value) return;
const navLinks = Array.from(document.querySelectorAll("nav a"));
const pathname = window.location.pathname.replace(/\/$/, "") || "/";
const activeNavElement = (navElement.value as Element).querySelector(
`a[href="${pathname}"]`
);
navLinks.forEach((link) => {
if (!navElement.value) return;
const pathname = window.location.pathname.replace(/\/$/, "");
const activeNavElement = (navElement.value as Element).querySelector(
`a[href="${pathname}"]`
);
if (link == activeNavElement) {
link.classList.remove("text-neutral-400");
link.classList.add("scale-90", "text-white");
} else {
link.classList.remove("scale-90", "text-white");
link.classList.add("text-neutral-400");
}
link.classList.remove("scale-90", "text-white");
link.classList.add("text-neutral-400");
});
activeNavElement?.classList.add("scale-90", "text-white");
activeNavElement?.classList.remove("text-neutral-400");
}
const navElement = ref(null);
Expand Down

0 comments on commit 1c8ecfb

Please sign in to comment.