css3动画animation的基本使用方法,基本使用,语法格式,动画案例
程序员文章站
2022-03-01 20:51:09
...
-
什么是动画
- 动画是
CSS3
中最具颠覆性的特征之一,可通过设置多个节点来精确的控制一个或者一组动画,从而实现复杂的动画效果
- 动画是
-
动画的基本使用
- 先定义动画
- 在调用定义好的动画
-
语法格式(定义动画)
@keyframes 动画名称 { 0% { width: 100px; } 100% { width: 200px } }
-
语法格式(使用动画)
div { /* 调用动画 */ animation-name: 动画名称; /* 持续时间 */ animation-duration: 持续时间; }
-
动画序列
- 0% 是动画的开始,100 % 是动画的完成,这样的规则就是动画序列
- 在 @keyframs 中规定某项 CSS 样式,就由创建当前样式逐渐改为新样式的动画效果
- 动画是使元素从一个样式逐渐变化为另一个样式的效果,可以改变任意多的样式任意多的次数
- 用百分比来规定变化发生的时间,或用
from
和to
,等同于 0% 和 100%
-
代码演示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #ccc;
}
.box {
position: relative;
width: 500px;
height: 500px;
margin: 100px auto;
border: 5px solid #000;
}
.box div {
position: absolute;
bottom: 0;
right: 0;
width: 100px;
height: 100px;
background-color: #00f;
animation: move;
animation-duration: 5s;
}
@keyframes move {
0% {
bottom: 0;
right: 0;
border-radius: 50%;
}
25% {
bottom: 0;
right: 400px;
border-radius: 0;
}
50% {
bottom: 400px;
left: 0;
}
75% {
bottom: 400px;
left: 400px;
border-radius: 50%;
}
100% {
bottom: 0;
left: 400px;
}
}
</style>
</head>
<body>
<div class="box">
<div></div>
</div>
</body>
</html>
8.这个就是关于动画的一个小案例,使用动画记得先定义,然后在动用,添加动画过度时间,记得谁做动画给谁家,动画时间加在本身上。
上一篇: Animation使用方法(一)
下一篇: animation属性详解