I am creating a stop-motion animation of a running cat. I have already all the slides ready. But it doesn't seem to work properly:
div {
animation: run 1s steps(10) infinite;
-webkit-animation: run 1s steps(10) infinite;
background: url(http://stash.rachelnabors.com/img/codepen/tuna_sprite.png) 0 0;
background-repeat: no-repeat;
height: 200px;
width: 400px;
}
@keyframes run {
0% {background-position: 100% 0; }
100% {background-position: 100% -2591px; }
}
@-webkit-keyframes run {
0% {background-position: 100% 0; }
100% {background-position: 100% -2591px; }
}
<div></div>
The only way to truly pause an animation in CSS is to use the animation-play-state property with a paused value. In JavaScript, the property is “camelCased” as animationPlayState and set like this: element.
CSS animations make it possible to animate transitions from one CSS style configuration to another. Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation's style, as well as possible intermediate waypoints.
Actually you have 13 slides. So put steps(13)
div {
animation: run 1s steps(13) infinite;
-webkit-animation: run 1s steps(13) infinite;
background: url(http://stash.rachelnabors.com/img/codepen/tuna_sprite.png) 0 0;
background-repeat: no-repeat;
height: 200px;
width: 400px;
}
@keyframes run {
0% {background-position: 100% 0; }
100% {background-position: 100% -2591px; }
}
@-webkit-keyframes run {
0% {background-position: 100% 0; }
100% {background-position: 100% -2591px; }
}
<div></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With