-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (26 loc) · 860 Bytes
/
Copy pathscript.js
File metadata and controls
31 lines (26 loc) · 860 Bytes
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
const menuButton = document.querySelector(".menu-toggle");
const navigation = document.querySelector(".site-nav");
const navigationLinks = document.querySelectorAll(".site-nav a");
function closeMenu() {
if (!navigation || !menuButton) {
return;
}
navigation.classList.remove("is-open");
document.body.classList.remove("menu-open");
menuButton.setAttribute("aria-expanded", "false");
}
if (menuButton && navigation) {
menuButton.addEventListener("click", () => {
const isOpen = navigation.classList.toggle("is-open");
document.body.classList.toggle("menu-open", isOpen);
menuButton.setAttribute("aria-expanded", String(isOpen));
});
}
navigationLinks.forEach((link) => {
link.addEventListener("click", closeMenu);
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
closeMenu();
}
});