动画
1. animation-name
- 定义动画名称
- 格式:animatio-name: move;
2. animation-duration
- 规定动画时长
- 格式:animation-duration: 3s;
3. animation-timing-function
- 规定动画如何完成一个周期
- 格式:animation-timing-function: ease;
linear |
动画从头到尾的速度是相同的。 |
ease |
默认。动画以低速开始,然后加快,在结束前变慢。 |
ease-in |
动画以低速开始。 |
ease-out |
动画以低速结束。 |
ease-in-out |
动画以低速开始和结束。 |
4. animation-delay
- 规定动画在启动前的延迟时间
- 格式:animation-delay: 3s;
5. animation-iteration-count
- 规定动画播放次数
- 格式:animation-iteration-count: 3;
- infinite属性值:无限次播放
6. animation-direction
- 规定是否应该轮流反向播放动画,如果动画被设置为只播放一次,该属性将不起作用
- 格式:animation-direction: normal;
值 |
描述 |
normal |
默认值。动画按正常播放。 |
reverse |
动画反向播放。 |
alternate |
动画在奇数次(1、3、5...)正向播放,在偶数次(2、4、6...)反向播放。 |
alternate-reverse |
动画在奇数次(1、3、5...)反向播放,在偶数次(2、4、6...)正向播放。 |
7. animation-play-state
- 规定动画是否正在运行或已暂停
- 格式:animation-play-state: running(默认值);
- paused属性值:指定暂停动画;running属性值:指定正在运行动画;
8. animation-fill-mode
- 规定当动画不播放时(当动画完成时,或当动画有一个延迟未开始播放时),要应用到元素的样式
- 格式:animation-fill-mode: both;
值 |
描述 |
none |
默认值。动画在动画执行之前和之后不会应用任何样式到目标元素。 |
forwards |
在动画结束后(由 animation-iteration-count 决定),动画将应用该属性值。 |
backwards |
动画将应用在 animation-delay 定义期间启动动画的第一次迭代的关键帧中定义的属性值。这些都是 from 关键帧中的值(当 animation-direction 为 "normal" 或 "alternate" 时)或 to 关键帧中的值(当 animation-direction 为 "reverse" 或 "alternate-reverse" 时)。 |
both |
动画遵循 forwards 和 backwards 的规则。也就是说,动画会在两个方向上扩展动画属性。 |
示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1{
width: 600px;
height: 600px;
border: 1px solid #000;
margin: 100px auto;
}
.box2{
width: 100px;
height: 100px;
background-color: #f00;
animation-name: move;
animation-duration: 3s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state: running;
animation-fill-mode: both;
}
.box1:hover .box2{
animation-play-state: paused;
}
@keyframes move{
0%{
transform: translate(0px,0px) rotateZ(0deg);
background-color: #000;
}
25%{
transform: translate(500px,0px) rotateZ(1000deg);
background-color: #0f0;
}
50%{
transform: translate(500px,500px) rotateZ(2000deg);
background-color: #00f;
width: 300px;
}
75%{
transform: translate(0px,500px) rotateZ(1000deg);
background-color: #ff0;
}
100%{
transform: translate(0px,0px) rotateZ(0deg);
background-color: #0ff;
}
}
</style>
</head>
<body>
<div class="box1">
<div class="box2">
</div>
</div>
</body>
</html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!