mirror of
https://github.com/thomasjsn/hugo-theme-hello-friend.git
synced 2024-11-14 20:35:07 +01:00
17 lines
583 B
JavaScript
17 lines
583 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.addEventListener("click", () => menu && menu.classList.toggle("hidden"));
|
|
|
|
window.addEventListener("resize", isMobileMenu);
|