html - css没有动画定时功能
问题描述
如何让动画直接切换帧?必须没有像线性或其他任何时间函数。我需要帧直接在帧之间切换,而无需在值之间进行任何操作。
例如:
0% -> top: 20px
100% -> top: 400px
应该在时间 t 中直接进入 400px,而不需要经过 100、200、245 或其他任何时间。
解决方案
您可以使用动画延迟:
.a{
width: 50%;
height: 100px;
position: absolute;
top: 20px;
background-color: #1F8CCA;
margin-top: 20px;
animation:anim 0s 1;
-webkit-animation:anim 0s 1;
animation-fill-mode: forwards;
animation-delay:2s;
-webkit-animation-delay:2s; /* Safari and Chrome */
-webkit-animation-fill-mode: forwards;
}
@keyframes anim{
from {top: 20px;}
to {top: 400px;}
}
@-webkit-keyframes anim{
from {top: 20px;}
to {top: 400px;}
}
<div class="a">
<div>
您可以定义具有不同延迟的多个动画。不确定这是最好的方法,但它确实有效。
.a{
width: 50%;
height: 100px;
position: absolute;
top: 20px;
background-color: #1F8CCA;
margin-top: 20px;
animation:anim 0s 1, anim-back 0s 1, anim 0s 1;
-webkit-animation:anim 0s 1, anim-back 0s 1, anim 0s 1;
animation-fill-mode: forwards;
animation-delay:1s, 2s, 3s;
-webkit-animation-delay:1s, 2s, 3s; /* Safari and Chrome */
animation-iteration-count: 1;
-webkit-animation-iteration-count: 1;
}
@keyframes anim{
from {top: 20px;}
to {top: 400px;}
}
@-webkit-keyframes anim{
from {top: 20px;}
to {top: 400px;}
}
@keyframes anim-back{
from {top: 400px;}
to {top: 20px;}
}
@-webkit-keyframes anim-back{
from {top: 400px;}
to {top: 20px;}
}
<div class="a">
<div>
推荐阅读
- python - Pyomo Set 和 Python set 有什么区别吗?
- sql - 使用存储过程的返回值进行 SSIS 循环
- jquery - 使用变量构建选择选项
- matching - 记录与多个数据集的链接
- javascript - 如何修复我的代码以确定整个字符串是否按字母顺序排列?
- scala - 如何使用 scala 将具有列表值的案例类正确展平为另一个案例类
- amazon-web-services - 使用 Amazon Cognito 进行 Hasura Webhook 身份验证
- python - PGM 文件无法在 tkinter 窗口中打开,“无法识别图像文件中的数据”
- macos - Mac 上的 Puppeteer/chromium 长期提示“接受传入的网络连接?”
- angular-ui-grid - 为什么 UI-Grid 选择会抛出 JS 错误