При клике на кнопку кнопка опускаеться вниз и назад. Помогите сделать так чтоб при следуйщем клике она снову виполняла анимацию.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Anim</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<button>Stick</button>
</div>
<script src="app.js"></script>
</body>
</html>
body {
background-color: grey;
}
.container {
height: 100vh;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.container button {
width: 100px;
height: 100px;
}
@keyframes btn {
0% {
margin-top: 50px;
}
50% {
margin-top: 60px;
}
100% {
margin-top: 0;
}
}
button.on {
animation: btn 900ms linear ;
}
let btn = document.querySelector("button")
btn.addEventListener("click", function () {
if (!btn.classList.contains("on")) {
btn.classList.add("on")
}
else {
btn.classList.remove("on")
}
})