From f82d05eb742aae008f40dde596a2417fb645d59f Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Tue, 10 Aug 2021 10:03:41 -0300 Subject: [PATCH] added functionality to toggle menu with click event --- assets/script.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/assets/script.js b/assets/script.js index e69de29..ef3a6c2 100644 --- a/assets/script.js +++ b/assets/script.js @@ -0,0 +1,20 @@ +document.addEventListener("DOMContentLoaded", () => { + // just open the menu + document.querySelectorAll(['[data-menu-open]']).forEach((el) => el.addEventListener('click', event => { + event.preventDefault(); + const menu = document.getElementById(el.getAttribute('data-menu-open')); + menu.style.display = 'block'; + })); + // just close the menu + document.querySelectorAll(['[data-menu-close]']).forEach((el) => el.addEventListener('click', event => { + event.preventDefault(); + const menu = document.getElementById(el.getAttribute('data-menu-close')); + menu.style.display = 'none'; + })); + // switch between open and close + document.querySelectorAll(['[data-menu-toggle]']).forEach((el) => el.addEventListener('click', event => { + event.preventDefault(); + const menu = document.getElementById(el.getAttribute('data-menu-toggle')); + menu.style.display = menu.style.display == 'block'? 'none': 'block'; + })); +});