24 lines
794 B
JavaScript
24 lines
794 B
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
const navLinks = Array.from(document.querySelectorAll(".main-nav a, .mobile-nav-links a"));
|
|
|
|
navLinks.forEach((link) => {
|
|
link.addEventListener("click", (event) => {
|
|
const targetId = link.getAttribute("href");
|
|
if (!targetId || !targetId.startsWith("#")) {
|
|
return;
|
|
}
|
|
|
|
const targetSection = document.querySelector(targetId);
|
|
if (!targetSection) {
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
targetSection.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
|
|
navLinks.forEach((item) => item.classList.remove("is-active"));
|
|
link.classList.add("is-active");
|
|
});
|
|
});
|
|
});
|