diff --git a/burger.js b/burger.js index 565aae0..12ff1ed 100644 --- a/burger.js +++ b/burger.js @@ -1,6 +1,24 @@ // @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0-1.0 +// burger.js + function toggleMenu() { - const menu = document.querySelector(".menu"); - menu.classList.toggle("active"); + const menu = document.querySelector(".menu"); + menu.classList.toggle("active"); + + // Add event listener to close menu when clicking anywhere on the document + if (menu.classList.contains("active")) { + document.addEventListener("click", closeMenu); + } else { + document.removeEventListener("click", closeMenu); + } } -// @license-end \ No newline at end of file + +function closeMenu(event) { + const menu = document.querySelector(".menu"); + if (!menu.contains(event.target) && !event.target.classList.contains("burger-menu")) { + menu.classList.remove("active"); + document.removeEventListener("click", closeMenu); + } +} + +// @license-end diff --git a/header-folder.js b/header-folder.js index 0ccefab..1713b6a 100644 --- a/header-folder.js +++ b/header-folder.js @@ -12,7 +12,7 @@ class Header extends HTMLElement {
- +