我想每1000毫秒立即翻转一次图像。我正在尝试,但是动画可以完成它应该做的事情(逐渐翻转图片)。如果我可以立即翻转图片,它将给人以“ walking鸭子”的感觉。我知道我可以使用setInterval(),但我只想在CSS中这样做。
.duck {
position: absolute;
animation: flip-me;
animation-duration: 1000ms;
animation-direction: alternate;
animation-iteration-count: infinite;
}
@keyframes flip-me {
0% { transform: scaleX(1) }
100% { transform: scaleX(-1) }
}
答案 0 :(得分:2)
您可以考虑使用steps()
img {
animation: flip-me 2s steps(1) infinite;
}
@keyframes flip-me {
50% { /*Pay attention: it's 50% not 100% !!*/
transform: scaleX(-1)
}
}
/*no need 0% or 100% state as they be set by default to scaleX(1)*/
<img src="https://picsum.photos/200/200?image=1069">