Codigo para hacer un mega menu
Codigo para hacer un mega menu
h-nav
h-nav-item
document.addEventListener('DOMContentLoaded', function() {
// Add 'click' event to the document to detect clicks outside the menu
document.addEventListener('click', removeParentClass);
//Menu Mobile
const navbarToggler = document.querySelector(".h-navbar-toggler");
const nav = document.querySelector(".h-nav");
let navHeight = 0;
navbarToggler.addEventListener("click", () => {
const computedStyles = window.getComputedStyle(nav);
const isNavHidden = computedStyles.getPropertyValue('display') ===
'none' || computedStyles.getPropertyValue('height') === '0px';
if (isNavHidden) {
// Show the navigation menu and animate its opening
nav.style.display = "block";
navHeight = nav.scrollHeight;
nav.style.height = "0";
setTimeout(() => {
nav.style.height = navHeight + "px";
// Add an event listener to set the height to "auto" when
the animation is complete
nav.addEventListener("transitionend", () => {
nav.style.height = "auto";
nav.removeEventListener("transitionend");
});
}, 10);
} else {
// Animate the closing of the navigation menu and then hide it
nav.style.height = navHeight + "px";
setTimeout(() => {
nav.style.height = "0";
setTimeout(() => {
nav.style.display = "none";
}, 200);
// Add an event listener to set the height to "auto" when
the animation is complete
nav.addEventListener("transitionend", () => {
nav.style.height = "auto";
nav.removeEventListener("transitionend");
});
}, 10);
}
});
//If the size is greater than 992px, the nav styles are removed
function removeNavStyles() {
if (window.innerWidth > 992) {
nav.removeAttribute("style");
}
}
window.addEventListener("resize", removeNavStyles);
});