-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (31 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
35 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Mobile nav toggle + tiny niceties
const navToggle = document.getElementById("navToggle");
const navMenu = document.getElementById("navMenu");
if (navToggle && navMenu) {
navToggle.addEventListener("click", () => {
const open = navMenu.classList.toggle("isOpen");
navToggle.setAttribute("aria-expanded", String(open));
});
// Close menu after clicking a link (mobile)
navMenu.querySelectorAll("a").forEach((a) => {
a.addEventListener("click", () => {
navMenu.classList.remove("isOpen");
navToggle.setAttribute("aria-expanded", "false");
});
});
}
// Year in footer
const year = document.getElementById("year");
if (year) year.textContent = String(new Date().getFullYear());
// Smooth scroll for in-page anchors
document.querySelectorAll('a[href^="#"]').forEach((link) => {
link.addEventListener("click", (e) => {
const id = link.getAttribute("href");
if (!id || id === "#") return;
const el = document.querySelector(id);
if (!el) return;
e.preventDefault();
el.scrollIntoView({ behavior: "smooth", block: "start" });
history.pushState(null, "", id);
});
});