-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.js
More file actions
32 lines (24 loc) · 832 Bytes
/
services.js
File metadata and controls
32 lines (24 loc) · 832 Bytes
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
const hamburger = document.getElementById('hamburger');
const dropdownMenu = document.getElementById('dropdown-menu');
const toggleMenu = () => {
if (dropdownMenu.style.display === 'block') {
dropdownMenu.style.display = 'none';
} else {
dropdownMenu.style.display = 'block';
}
};
const checkWidth = () => {
if (window.innerWidth > 768) {
dropdownMenu.style.display = 'none';
}
};
hamburger.addEventListener('click', toggleMenu);
window.addEventListener('resize', checkWidth);
// Close the dropdown if the user clicks outside of it
window.addEventListener('click', (event) => {
if (!event.target.matches('#hamburger')) {
if (dropdownMenu.style.display === 'block') {
dropdownMenu.style.display = 'none';
}
}
});