final solving of menu hover bug

This commit is contained in:
Kevin Veen-Birkenbach 2025-01-14 21:05:26 +01:00
parent b74ff2da78
commit c24e35c4e8

View File

@ -9,7 +9,6 @@ document.addEventListener('DOMContentLoaded', () => {
function onMouseEnter() { function onMouseEnter() {
clearTimeout(timeout); clearTimeout(timeout);
openMenu(item, isTopLevel); openMenu(item, isTopLevel);
refreshEventListeners();
} }
function onMouseLeave() { function onMouseLeave() {
@ -33,20 +32,18 @@ document.addEventListener('DOMContentLoaded', () => {
} else { } else {
openMenu(item, isTopLevel); openMenu(item, isTopLevel);
} }
refreshEventListeners();
}); });
}); });
} }
function refreshEventListeners() { function addAllMenuEventListeners() {
const updatedMenuItems = document.querySelectorAll('.nav-item.dropdown'); const updatedMenuItems = document.querySelectorAll('.nav-item.dropdown');
const updatedSubMenuItems = document.querySelectorAll('.dropdown-submenu'); const updatedSubMenuItems = document.querySelectorAll('.dropdown-submenu');
addMenuEventListeners(updatedMenuItems, true); addMenuEventListeners(updatedMenuItems, true);
addMenuEventListeners(updatedSubMenuItems, false); addMenuEventListeners(updatedSubMenuItems, false);
} }
addMenuEventListeners(menuItems, true); addAllMenuEventListeners();
addMenuEventListeners(subMenuItems, false);
// Globale Klick-Listener, um Menüs zu schließen, wenn außerhalb geklickt wird // Globale Klick-Listener, um Menüs zu schließen, wenn außerhalb geklickt wird
document.addEventListener('click', () => { document.addEventListener('click', () => {
@ -57,10 +54,10 @@ document.addEventListener('DOMContentLoaded', () => {
item.classList.add('open'); item.classList.add('open');
const submenu = item.querySelector('.dropdown-menu'); const submenu = item.querySelector('.dropdown-menu');
if (submenu) { if (submenu) {
adjustMenuPosition(submenu, item, isTopLevel);
submenu.style.display = 'block'; submenu.style.display = 'block';
submenu.style.opacity = '1'; submenu.style.opacity = '1';
submenu.style.visibility = 'visible'; submenu.style.visibility = 'visible';
adjustMenuPosition(submenu, item, isTopLevel);
} }
} }