-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmenu.js
More file actions
41 lines (34 loc) · 1.54 KB
/
submenu.js
File metadata and controls
41 lines (34 loc) · 1.54 KB
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
40
document.addEventListener('DOMContentLoaded', function () {
const hostingNavItem = document.querySelector('.nav-item-hosting');
const submenu = hostingNavItem?.querySelector('.submenu-hosting');
const hostingLink = hostingNavItem?.querySelector('a');
const burgerMenuToggle = document.getElementById('menu-toggle');
// Disable submenu toggle on smaller screens
function disableSubmenuOnSmallScreens() {
if (window.innerWidth < 768) {
hostingLink.removeEventListener('mouseenter', showSubmenu);
hostingLink.removeEventListener('focus', showSubmenu);
hostingLink.removeEventListener('mouseleave', hideSubmenu);
hostingLink.removeEventListener('blur', hideSubmenu);
hostingLink.href = hostingLink.dataset.href; // Restore normal link behavior
} else {
hostingLink.addEventListener('mouseenter', showSubmenu);
hostingLink.addEventListener('focus', showSubmenu);
hostingLink.addEventListener('mouseleave', hideSubmenu);
hostingLink.addEventListener('blur', hideSubmenu);
}
}
// Show submenu
function showSubmenu() {
submenu.style.opacity = '1';
submenu.style.visibility = 'visible';
}
// Hide submenu
function hideSubmenu() {
submenu.style.opacity = '0';
submenu.style.visibility = 'hidden';
}
// Ensure submenu behavior adapts to screen size
window.addEventListener('resize', disableSubmenuOnSmallScreens);
disableSubmenuOnSmallScreens();
});