Fixed Menu Autoclose on click of button

This commit is contained in:
Stan Turing 2024-12-18 11:46:43 +01:00
parent 9d66b9e507
commit 90a4e9e740
3 changed files with 12 additions and 9 deletions

View file

@ -90,13 +90,6 @@
<a class="footer-link" href="imprint.html">Impressum</a>
<p class="copyright">© 2023 - <span id="year"></span> Patrick Gerhartz | Alle Rechte vorbehalten.</p>
</div>
<script>
hamburger = document.querySelector(".hamburger");
hamburger.onclick = function() {
navBar = document.querySelector(".nav-bar");
navBar.classList.toggle("active");
}
document.getElementById("year").innerHTML = new Date().getFullYear();
</script>
<script src="script.js"></script>
</body>
</html>

View file

@ -2,4 +2,14 @@ hamburger = document.querySelector(".hamburger");
hamburger.onclick = function() {
navBar = document.querySelector(".nav-bar");
navBar.classList.toggle("active");
}
}
const menuButtons = document.querySelectorAll(".nav-bar a");
menuButtons.forEach(button => {
button.addEventListener("click", () => {
const navBar = document.querySelector(".nav-bar");
navBar.classList.remove("active"); // Menü schließen
});
});
document.getElementById("year").innerHTML = new Date().getFullYear();

View file