-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
56 lines (49 loc) · 1.53 KB
/
main.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import "./app/scss/style.scss";
import {
disableBodyScroll,
enableBodyScroll,
clearAllBodyScrollLocks,
} from "body-scroll-lock";
const main = document.querySelector("#main");
const footer = document.querySelector("#footer");
const btnOpen = document.querySelector("#btnOpen");
const btnClose = document.querySelector("#btnClose");
const menuTopNav = document.querySelector("#menuTopNav");
const overlay = document.querySelector("#overlay");
const breakpint = window.matchMedia("(width < 43.75em)");
const setupTopNav = () => {
if (breakpint.matches) {
menuTopNav.setAttribute("inert", "");
} else {
closeMobileMenu();
menuTopNav.removeAttribute("inert");
}
};
setupTopNav();
btnOpen.addEventListener("click", openMobileMenu);
btnClose.addEventListener("click", closeMobileMenu);
breakpint.addEventListener("change", () => {
setupTopNav();
});
function openMobileMenu() {
btnOpen.setAttribute("aria-expanded", "true");
main.setAttribute("inert", "");
footer.setAttribute("inert", "");
menuTopNav.removeAttribute("inert");
menuTopNav.style.transitionDuration = "400ms";
overlay.style.transitionDuration = "400ms";
disableBodyScroll(menuTopNav);
btnClose.focus();
}
function closeMobileMenu() {
btnOpen.setAttribute("aria-expanded", "false");
main.removeAttribute("inert");
footer.removeAttribute("inert");
menuTopNav.setAttribute("inert", "");
enableBodyScroll(menuTopNav);
btnOpen.focus();
setTimeout(() => {
menuTopNav.removeAttribute("style");
overlay.removeAttribute("style");
}, 500);
}