-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhamburger.js
More file actions
21 lines (19 loc) · 912 Bytes
/
Copy pathhamburger.js
File metadata and controls
21 lines (19 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
window.addEventListener('load', function () {
document.getElementById('hamburger').addEventListener('click', function (evt) {
evt.target.parentNode.querySelector('ul').classList.toggle('show');
});
this.document.getElementById('nav-main').querySelector("span[data-action='close']").addEventListener('click', function (evt) {
evt.target.parentNode.classList.remove('show');
})
// Close the menu when clicking outside it (ignoring clicks on the hamburger itself,
// so opening it doesn't immediately get closed by this same click).
document.addEventListener('click', function (evt) {
var menu = document.getElementById('nav-main').querySelector('ul');
var hamburger = document.getElementById('hamburger');
if (menu.classList.contains('show')
&& !menu.contains(evt.target)
&& !hamburger.contains(evt.target)) {
menu.classList.remove('show');
}
});
})