Here is my custom box:
<div class="customBox"></div>
It features a unique animation:
.customBox{
animation:right 5s;
animation-fill-mode:forwards;
padding:50px;
width:0px;
height:0px;
display:block;
background-color:black;
}
@keyframes
right{from{left:0px;}to{left:300px
;}}
@keyframes
left{from{right:0px;}to{right:300p
x;}}
I also have two buttons:
<button onclick="leftFunction">left</button>
<button onclick="rightFunction">right</button>
If I click left, the box will move to the left. However, if I click right while it's moving left, I want the left animation to stop and the right animation to start from the current position without teleporting.
I'm seeking assistance on this issue. I'm new to coding resources like Stack Overflow.
Below is the JavaScript code:
function leftFunction() {
document.getElementById("myDIV").style.animation
= "left 4s";
}
function rightFunction() {
document.getElementById("myDIV").style.
animation = "right 4s";
}