如何切换scaleX以在没有动画的情况下翻转图像

问题描述 投票:0回答:1

我想每1000ms立即翻转一个图像。我正在尝试,但动画做了它应该做的事情(逐渐翻转图片)。如果我可以立即翻转图片,它会给出一只行走鸭子的想法。我知道我可以使用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) }
}
css css-transforms
1个回答
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">
© www.soinside.com 2019 - 2024. All rights reserved.