-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
59 lines (53 loc) · 2.27 KB
/
menu.js
File metadata and controls
59 lines (53 loc) · 2.27 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
document.addEventListener('DOMContentLoaded', function () {
const navLinks = document.getElementById('nav-links');
const contentWrapper = document.getElementById('content-wrapper');
const menuToggle = document.getElementById('menu-toggle');
const hostingNavItem = document.querySelector('.nav-item-hosting');
const submenu = document.querySelector('.submenu-hosting');
// Toggle for the burger menu
function toggleMenu() {
navLinks.classList.toggle('active');
if (navLinks.classList.contains('active')) {
contentWrapper.style.marginTop = `${navLinks.offsetHeight}px`;
} else {
contentWrapper.style.marginTop = '0';
}
}
// Prevent submenu dropdown in mobile view
function handleHostingClick(event) {
if (window.innerWidth < 1024) {
// Mobile view: treat hosting as a simple link
window.location.href = '#'; // Replace '#' with your desired link
event.preventDefault();
}
}
// Show/hide submenu on hover (for larger screens)
function handleSubmenuVisibility(show) {
if (window.innerWidth >= 1024) {
submenu.style.opacity = show ? '1' : '0';
submenu.style.visibility = show ? 'visible' : 'hidden';
contentWrapper.style.marginTop = show ? `${submenu.offsetHeight}px` : '0';
}
}
// Event listeners for the hosting item
if (hostingNavItem && submenu) {
hostingNavItem.addEventListener('mouseenter', () => handleSubmenuVisibility(true));
hostingNavItem.addEventListener('mouseleave', () => handleSubmenuVisibility(false));
hostingNavItem.addEventListener('click', handleHostingClick);
}
// Event listeners for the burger menu
if (menuToggle) {
menuToggle.addEventListener('click', toggleMenu);
}
// Adjust on resize
window.addEventListener('resize', function () {
if (window.innerWidth >= 1024) {
// Reset styles for desktop view
submenu.style.opacity = '0';
submenu.style.visibility = 'hidden';
contentWrapper.style.marginTop = '0';
} else if (navLinks.classList.contains('active')) {
contentWrapper.style.marginTop = `${navLinks.offsetHeight}px`;
}
});
});