css - 如何在没有动画的情况下切换 scaleX 来翻转图像
问题描述
我想每 1000 毫秒立即翻转一张图像。我正在尝试,但动画做了它应该做的事情(逐渐翻转图片)。如果我可以立即翻转图片,它将给人一种会走路的鸭子的想法。我知道我可以使用 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) }
}
解决方案
你可以考虑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">
推荐阅读
- apache-spark - 使用 Apache Spark 进行更改数据捕获
- c# - 如何修复“MaterialDesignFloatingHintTextBox”无法解决
- jenkins - 如何获取安装特定插件的 Jenkins 用户?
- asynchronous - 无法让计算在颤振上工作
- c# - 在鼠标悬停的图像标签中放大图像
- firebase - Firebase Google Auth 离线 access_type 以获取 refresh_token
- sympy - 如何在 sympy 中扩展具有多个变量的对数?
- php - 收到新请求时中止繁重的 apache 请求
- sql - 具有 oracle 数据库表的搜索引擎
- c++ - 如何使用 c++ 中的 ipp 库从信号中生成 fft?