Skip to content

Instantly share code, notes, and snippets.

@malchata
Created July 17, 2020 04:02
Show Gist options
  • Save malchata/d89696861b939a2dfa374924d9b07609 to your computer and use it in GitHub Desktop.
Save malchata/d89696861b939a2dfa374924d9b07609 to your computer and use it in GitHub Desktop.
console.time("Evaluate script.");
const menuToggleButton = document.getElementById("menu-toggle");
const closeMenuButton = document.getElementById("close-menu");
const menu = document.getElementById("menu");
const overlay = document.getElementById("menu-overlay");
let menuVisible = false;
const openMenu = function () {
console.time("Menu open.");
overlay.removeAttribute("hidden");
menu.classList.add("menu--visible");
console.timeEnd("Menu open.");
return true;
};
const closeMenu = function () {
console.time("Menu close.");
overlay.setAttribute("hidden", "hidden");
menu.classList.remove("menu--visible");
console.timeEnd("Menu close.");
return false;
};
menuToggleButton.addEventListener("click", () => {
if (!menuVisible) {
menuVisible = openMenu();
return;
}
menuVisible = closeMenu();
});
closeMenuButton.addEventListener("click", () => {
menuVisible = closeMenu();
});
console.timeEnd("Evaluate script.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment