generated from dynamikaweb/yii2-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added functionality to toggle menu with click event
- Loading branch information
1 parent
016d518
commit f82d05e
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
})); | ||
}); |