til/themes/hello-friend-ng/assets/js/menu.js
2020-09-13 19:51:28 +01:00

23 lines
616 B
JavaScript

// Mobile menu
const menuTrigger = document.querySelector(".menu-trigger");
const menu = document.querySelector(".menu");
const mobileQuery = getComputedStyle(document.body).getPropertyValue(
"--phoneWidth"
);
const isMobile = () => window.matchMedia(mobileQuery).matches;
const isMobileMenu = () => {
menuTrigger && menuTrigger.classList.toggle("hidden", !isMobile());
menu && menu.classList.toggle("hidden", isMobile());
};
isMobileMenu();
menuTrigger &&
menuTrigger.addEventListener(
"click",
() => menu && menu.classList.toggle("hidden")
);
window.addEventListener("resize", isMobileMenu);