From abdaf54147fb800b9c403db672172b138176c46c Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 14 Jan 2025 19:25:07 +0100 Subject: [PATCH] refaktored --- app/static/js/navigation.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/static/js/navigation.js b/app/static/js/navigation.js index 34bccdf..c5d3041 100644 --- a/app/static/js/navigation.js +++ b/app/static/js/navigation.js @@ -6,16 +6,22 @@ document.addEventListener('DOMContentLoaded', () => { items.forEach(item => { let timeout; - // Öffnen beim Hovern - item.addEventListener('mouseenter', () => { + function onMouseEnter() { clearTimeout(timeout); openMenu(item, isTopLevel); - }); + } + + function onMouseLeave() { + timeout = setTimeout(() => { + closeMenu(item); + }, 500); + } + + // Öffnen beim Hovern + item.addEventListener('mouseenter', onMouseEnter); // Verzögertes Schließen beim Verlassen - item.addEventListener('mouseleave', () => { - timeout = setTimeout(() => closeMenu(item), 500); - }); + item.addEventListener('mouseleave', onMouseLeave); // Öffnen und Position anpassen beim Klicken item.addEventListener('click', (e) => {