forked from drowl87/hextra_mirror
feat: hide navbar on mobile when heading links clicked (#584)
This commit is contained in:
parent
b2e6c30c7f
commit
49b1cd11ee
@ -23,6 +23,12 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
document.body.classList.toggle('md:hx-overflow-auto');
|
document.body.classList.toggle('md:hx-overflow-auto');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hideOverlay() {
|
||||||
|
// Hide the overlay
|
||||||
|
overlay.classList.remove(...overlayClasses);
|
||||||
|
overlay.classList.add('hx-bg-transparent');
|
||||||
|
}
|
||||||
|
|
||||||
menu.addEventListener('click', (e) => {
|
menu.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
toggleMenu();
|
toggleMenu();
|
||||||
@ -33,8 +39,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
overlay.classList.remove('hx-bg-transparent');
|
overlay.classList.remove('hx-bg-transparent');
|
||||||
} else {
|
} else {
|
||||||
// Hide the overlay
|
// Hide the overlay
|
||||||
overlay.classList.remove(...overlayClasses);
|
hideOverlay();
|
||||||
overlay.classList.add('hx-bg-transparent');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -43,7 +48,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
toggleMenu();
|
toggleMenu();
|
||||||
|
|
||||||
// Hide the overlay
|
// Hide the overlay
|
||||||
overlay.classList.remove(...overlayClasses);
|
hideOverlay();
|
||||||
overlay.classList.add('hx-bg-transparent');
|
});
|
||||||
|
|
||||||
|
// Select all anchor tags in the sidebar container
|
||||||
|
const sidebarLinks = sidebarContainer.querySelectorAll('a');
|
||||||
|
|
||||||
|
// Add click event listener to each anchor tag
|
||||||
|
sidebarLinks.forEach(link => {
|
||||||
|
link.addEventListener('click', (e) => {
|
||||||
|
// Check if the href attribute contains a hash symbol (links to a heading)
|
||||||
|
if (link.getAttribute('href') && link.getAttribute('href').startsWith('#')) {
|
||||||
|
// Only dismiss overlay on mobile view
|
||||||
|
if (window.innerWidth < 768) {
|
||||||
|
toggleMenu();
|
||||||
|
hideOverlay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user