css - 有没有办法精细控制 CSS 元素上的动画属性?
问题描述
我有这个代码:
transition: all 0.35s;
transition-delay: 0.25s;
transition-timing-function: cubic-bezier(.79,0,.46,1);
但如果我添加更多我想要动画的属性,结果会出现问题,所以我想做类似的事情:
transition: transform 0.35s/*duration*/ 0.25s /*delay*/ cubic-bezier(.79,0,.46,1),
opacity 0.25s/*duration*/ 1s /*delay*/ ease-in ;
我查看了速记属性,但找不到合适的组合。
解决方案
是的,您想要的是 CSS动画而不是 CSS 过渡。过渡用于创建从一种状态到另一种状态的平滑过渡,而动画允许您通过更改 css 属性来定义更复杂的行为。
它看起来像这样:
element {
animation-name: yourAnimationName;
animation-timing-function: cubic-bezier(.79,0,.46,1);
animation-delay: 0.25s;
}
@keyframes yourAnimationName {
// here you define which css properties to animate
}
您可以使用 from 和 to 定义关键帧:
@keyframes yourAnimationName {
from { background-color: red; }
to { background-color: yellow; }
}
或者您可以使用百分比定义多个关键帧(占整个动画的百分比):
@keyframes example {
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
如果您使用关键帧作为百分比,您也可能不需要三次贝塞尔计时函数。
我建议在这里阅读一些关于 css 动画的内容。
推荐阅读
- javascript - “useRefs”变量是 div 引用的初始值?
- javascript - SyntaxError:无法使用 json 解析绑定
- python - 如何将 pyautogui/win32gui 和 Pillow 一起使用?
- python - Pandas 根据列覆盖
- typescript - Ag 网格标题行展开和折叠
- camunda - ENGINE-09005 无法解析 BPMN 进程。错误:
- python - 装饰器使用 for 循环但不使用 while 循环
- python - 在 Django Rest Framework 中测试 PUT 方法
- javascript - Javasript 代码在 Safari 8/9 版本中不起作用
- python - 使用 nRF24L01+ 无线模块无法让 Raspberry Pi 4 和 Arduino 成功通信