Is there a way to create an animation that moves objects based on button clicks? For example, when the "Monday" button is pressed, the object with the correct color will move down. If any other button like "Tuesday" is clicked, the previous object will move up and the correct one will move down. Any help would be appreciated.
Check out this code snippet for reference:
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>