So i'm trying to create an arrow that rotates 180deg on every click (so up en down). But the transition only works for down, when the arrows goes up there is no smooth transition anymore.
My HTML
<button class="button-arrow" onClick="showItems()"> <img class="arrow-down" src="./src/arrow-down.svg"> </button>
<ul class="hidden-items">
<li>Red</li>
<li>Blue</li>
<li>Yellow</li>
</ul>
My JS file:
function showItems() {
var items = document.getElementsByClassName("hidden-items")[0];
var arrow = document.getElementsByClassName("arrow-down")[0]
if (items.style.display == "block") {
items.style.display = "none";
arrow.classList.toggle('rotate-arrow')
} else {
items.style.display = "block";
arrow.classList.toggle('rotate-arrow')
}
}
My CSS
.rotate-arrow {
transform: rotate(180deg);
transition: transform 0.5s;
}
Does anyone has any advice how to solve this problem ?