Witam, stworzyłem w Vue komponent menu mobilnego. Zawartość jeszcze jest pusta. Działa ale chciałbym prosić o porady. Usunąłem fragment <template> ponieważ nic on nie wnosi do tematu. Bardziej zastanawiam się czy można było funkcję toggleMenu inaczej napisać i oszczędzić sobie funkcji remove i add...
<script setup>
import { ref } from "vue";
const menuOpened = ref(false);
const toggleMobileMenu = () => {
const menu = document.getElementById("mobileMenu");
if (menuOpened.value === true) {
menuOpened.value = false;
console.log("Zamykamy menu!!");
menu.classList.remove("mobile-menu-open-animation");
menu.classList.add("mobile-menu-close-animation");
} else {
menuOpened.value = true;
console.log("Otwieramy menu!!!");
menu.classList.remove("mobile-menu-close-animation");
menu.classList.add("mobile-menu-open-animation");
}
};
</script>
<style>
.mobile-menu-open-animation {
animation-name: mobileMenuOpen;
animation-duration: 0.4s;
animation-timing-function: ease-in-out;
animation-fill-mode: forwards;
}
@keyframes mobileMenuOpen {
to {
transform: translateY(100%);
}
}
.mobile-menu-close-animation {
animation-name: mobileMenuClose;
animation-duration: 0.4s;
animation-timing-function: ease-in-out;
animation-fill-mode: forwards;
}
@keyframes mobileMenuClose {
from {
transform: translateY(100%);
}
to {
transform: translateY(-100%);
}
}
</style>