How can I make an animation? When I press a button like Monday, the object with the correct color will move down, and if it is not the button pressed like "Tuesday" the previous object will move up and the correct object will move down. Thank you in advance
Here is the example of code..
function myFunction(myColor) {
const square_day = document.getElementById("square")
switch (myColor) {
case "Monday":
square_day.style.borderColor = "#ff7f98";
square_day.style.backgroundColor = "#ff7f9880";
square_day.style.animation = "square-to-circle 1s .83s"
break
case "Tuesday":
square_day.style.borderColor = "#d7d77b";
square_day.style.backgroundColor = "#d7d77b80";
square_day.style.animation = "square-to-circle 1s .83s"
break
}
#square {
height: 500px;
width: 500px;
position: relative;
border-style: solid;
border: 10px solid;
background-color: grey;
margin-left: auto;
margin-right: auto;
border-color: black;
top: -700px;
}
@keyframes square-to-circle {
0% {
top: -700px
}
100% {
top: 0px;
}
}
<div class="container">
<div id="button-container">
<div class="button-group">
<button class="button" id="Monday" value="Monday" onclick="myFunction(this.value)">Monday</button>
<button class="button" id="Tuesday" value="Tuesday" onclick="myFunction(this.value)">Tuesday</button>
<button class="button" id="Wednesday" value="Wednesday" onclick="myFunction(this.value)">Wednesday</button>
<button class="button" id="Thursday" value="Thursday" onclick="myFunction(this.value)">Thursday</button>
<button class="button" id="Friday" value="Friday" onclick="myFunction(this.value)">Friday</button>
<button class="button" id="Saturday" value="Saturday" onclick="myFunction(this.value)">Saturday</button>
<button class="button" id="Sunday" value="Sunday" onclick="myFunction(this.value)">Sunday</button>
</div>
</div>
<div id="square-container">
<div id="square">
</div>
</div>
</div>
}that immediately crashes the code on run.