Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.