-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.js
39 lines (35 loc) · 1.13 KB
/
menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Helper function to enable or disable scrolling on body
function bodyScroll(allow) {
const body = document.querySelector('body');
if (allow) {
body.style.overflowY = 'visible';
// document.querySelector('.past-events').display = 'flex';
} else {
body.style.overflowY = 'hidden';
// document.querySelector('.past-events').display = 'none';
}
}
// Show the mobile menu and disable scrolling
document.querySelector('.hamburger-button').addEventListener('click', () => {
const menu = document.querySelector('.menu-options');
menu.classList.remove('hidden');
menu.classList.add('show');
bodyScroll(false);
});
// Helper function to close the mobile menu and enable scrolling
function closeMenu() {
const menu = document.querySelector('.menu-options');
menu.classList.add('hidden');
menu.classList.remove('show');
bodyScroll(true);
}
// Close the mobile menu
document.querySelector('.close-menu').addEventListener('click', () => {
closeMenu();
});
// When a tag is clicked, close the mobile menu
document.addEventListener('click', (e) => {
if (e.target.matches('.menu-options ul li a')) {
closeMenu();
}
});