Implemented hover submenüs

This commit is contained in:
Kevin Veen-Birkenbach 2025-01-09 14:42:38 +01:00
parent 7a66184a46
commit d59cc73470
5 changed files with 56 additions and 27 deletions

View File

@ -113,4 +113,27 @@ h3.footer-title{
.dropdown-menu.collapse.show { .dropdown-menu.collapse.show {
display: block; display: block;
} }
/* 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;
}

View File

@ -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');
});
});
});

28
app/static/js/submenus.js Normal file
View File

@ -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
}
});
});
});

View File

@ -39,7 +39,7 @@
<!-- Include modal --> <!-- Include modal -->
{% include "moduls/modal.html.j2" %} {% include "moduls/modal.html.j2" %}
<script src="{{ url_for('static', filename='js/dynamic-modal.js') }}"></script> <script src="{{ url_for('static', filename='js/dynamic-modal.js') }}"></script>
<script src="{{ url_for('static', filename='js/close-submenus.js') }}"></script> <script src="{{ url_for('static', filename='js/submenus.js') }}"></script>
<script src="{{ url_for('static', filename='js/tooltip.js') }}"></script> <script src="{{ url_for('static', filename='js/tooltip.js') }}"></script>
</body> </body>
</html> </html>

View File

@ -2,11 +2,11 @@
{% macro render_subitems(subitems) %} {% macro render_subitems(subitems) %}
{% for subitem in subitems %} {% for subitem in subitems %}
{% if subitem.subitems %} {% if subitem.subitems %}
<li class="dropdown-submenu"> <li class="dropdown-submenu position-relative">
<a class="dropdown-item dropdown-toggle" href="#" id="submenu-{{ loop.index }}" data-bs-toggle="collapse" data-bs-target="#submenu-content-{{menu_type}}-{{ loop.index }}" aria-expanded="false" title="{{ subitem.description }}"> <a class="dropdown-item dropdown-toggle" href="#" title="{{ subitem.description }}">
<i class="{{ subitem.icon.class }}"></i> {{ subitem.name }} <i class="{{ subitem.icon.class }}"></i> {{ subitem.name }}
</a> </a>
<ul class="dropdown-menu collapse" id="submenu-content-{{menu_type}}-{{ loop.index }}"> <ul class="dropdown-menu">
{{ render_subitems(subitem.subitems) }} {{ render_subitems(subitem.subitems) }}
</ul> </ul>
</li> </li>
@ -30,7 +30,6 @@
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}
<!-- Navigation Bar --> <!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid"> <div class="container-fluid">