From d59cc73470ed0b33e7e43328a7537f6c017b183f Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 9 Jan 2025 14:42:38 +0100 Subject: [PATCH] =?UTF-8?q?Implemented=20hover=20submen=C3=BCs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/css/default.css | 25 +++++++++++++++++++++- app/static/js/close-submenus.js | 21 ------------------- app/static/js/submenus.js | 28 +++++++++++++++++++++++++ app/templates/moduls/base.html.j2 | 2 +- app/templates/moduls/navigation.html.j2 | 7 +++---- 5 files changed, 56 insertions(+), 27 deletions(-) delete mode 100644 app/static/js/close-submenus.js create mode 100644 app/static/js/submenus.js diff --git a/app/static/css/default.css b/app/static/css/default.css index 6adc62e..d4b71fa 100644 --- a/app/static/css/default.css +++ b/app/static/css/default.css @@ -113,4 +113,27 @@ h3.footer-title{ .dropdown-menu.collapse.show { display: block; -} \ No newline at end of file +} + +/* Standardmäßig sind die Submenüs ausgeblendet */ +.dropdown-submenu .dropdown-menu { + display: none; + opacity: 0; + transition: opacity 0.3s ease-in-out; + position: absolute; + left: 100%; + top: 0; +} + +/* Beim Hover auf das Submenü-Element wird das Menü angezeigt */ +.dropdown-submenu:hover > .dropdown-menu { + display: block; + opacity: 1; + z-index: 1050; +} + +/* Um sicherzustellen, dass es nicht sofort verschwindet */ +.dropdown-submenu:hover > .dropdown-menu:hover { + display: block; + opacity: 1; +} diff --git a/app/static/js/close-submenus.js b/app/static/js/close-submenus.js deleted file mode 100644 index 1f5e2c6..0000000 --- a/app/static/js/close-submenus.js +++ /dev/null @@ -1,21 +0,0 @@ -document.addEventListener('DOMContentLoaded', () => { - const dropdownSubmenus = document.querySelectorAll('.dropdown-submenu > .dropdown-item'); - - dropdownSubmenus.forEach((submenu) => { - submenu.addEventListener('click', (event) => { - event.preventDefault(); - const targetMenu = document.querySelector(submenu.getAttribute('data-bs-target')); - const allSubmenus = document.querySelectorAll('.dropdown-menu.collapse'); - - // Schließe alle anderen Submenüs - allSubmenus.forEach((menu) => { - if (menu !== targetMenu) { - menu.classList.remove('show'); - } - }); - - // Toggle des aktuellen Submenüs - targetMenu.classList.toggle('show'); - }); - }); -}); diff --git a/app/static/js/submenus.js b/app/static/js/submenus.js new file mode 100644 index 0000000..4d611de --- /dev/null +++ b/app/static/js/submenus.js @@ -0,0 +1,28 @@ +document.addEventListener('DOMContentLoaded', () => { + const dropdownSubmenus = document.querySelectorAll('.dropdown-submenu'); + + dropdownSubmenus.forEach(submenu => { + let timeout; + + // Zeige das Submenü beim Hover + submenu.addEventListener('mouseenter', () => { + clearTimeout(timeout); + const menu = submenu.querySelector('.dropdown-menu'); + if (menu) { + menu.style.display = 'block'; + menu.style.opacity = '1'; + } + }); + + // Verstecke das Submenü nach 0.5 Sekunden + submenu.addEventListener('mouseleave', () => { + const menu = submenu.querySelector('.dropdown-menu'); + if (menu) { + timeout = setTimeout(() => { + menu.style.display = 'none'; + menu.style.opacity = '0'; + }, 500); // 0.5 Sekunden Verzögerung + } + }); + }); +}); diff --git a/app/templates/moduls/base.html.j2 b/app/templates/moduls/base.html.j2 index 3a2cd75..6123906 100644 --- a/app/templates/moduls/base.html.j2 +++ b/app/templates/moduls/base.html.j2 @@ -39,7 +39,7 @@ {% include "moduls/modal.html.j2" %} - + \ No newline at end of file diff --git a/app/templates/moduls/navigation.html.j2 b/app/templates/moduls/navigation.html.j2 index 483f1c3..6e29252 100644 --- a/app/templates/moduls/navigation.html.j2 +++ b/app/templates/moduls/navigation.html.j2 @@ -2,11 +2,11 @@ {% macro render_subitems(subitems) %} {% for subitem in subitems %} {% if subitem.subitems %} -