Skip to content

Commit

Permalink
added functionality to toggle menu with click event
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles authored Aug 10, 2021
1 parent 016d518 commit f82d05e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions assets/script.js
Original file line number Diff line number Diff line change
@@ -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';
}));
});

0 comments on commit f82d05e

Please sign in to comment.