<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="button">Start Game</button>
<img src="https://www.chelanfresh.com/wp-content/uploads/2018/11/apple.png" id="apple">
</body>
</html>
#button {
min-width: 300px;
min-height: 300px;
color: #313133;
}
#apple {
height: 38%;
width: 10%;
margin-top: 27%;
margin-left: 19%;
visibility: hidden;
animation-name: appleSlide;
animation-duration: 3s;
animation-iteration-count: 1;
animation-direction: normal;
animation-play-state: paused;
animation-delay: 1s;
}
@keyframes appleSlide {
0% {margin-left: -50%;}
100% {margin-left: 19%}
}
let apple = document.getElementById("apple")
let button = document.getElementById("button")
function activateAnimations() {
apple.style.animationPlayState = "running";
apple.style.visibility = "visible";
}
button.addEventListener("click", activateAnimations)
Моя анимация в основном начинается скрытой или невидимой, но как только пользователь нажимает на кнопку, изображение появляется и скользит к определенной позиции c. Я возился с animationPlayState безрезультатно, и анимация никогда не активируется.