css3动画特效
一、transform(转换动画、直接动画)
1.rotate(旋转)
- 包含三种状态,x、y、z三轴的变化
rotatex
、rotatey
、rotatez
(默认)- 旋转(rotate)实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>rotate</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
margin:15% auto;
transform: rotate(45deg);
}
/*动画写在主样式里,页面加载完成之后就执行*/
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![rotate实例](https://i-blog.csdnimg.cn/blog_migrate/fb232211de380d66da315afba81cff3d.gif)
2.translate(平移)
- 包含三种状态,x、y、z三轴的变化
translatex
(默认)、translatey
、translatez
- 平移(translate)实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>translate</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
transform: translate(100px);
}
/*动画写在主样式里,页面加载完成之后就执行*/
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![translate实例](https://i-blog.csdnimg.cn/blog_migrate/e3aa2e0424134af623eb04758bab255a.gif)
3.skew(变形)
- 包含两种状态,x和y的变化
skewx
(默认)、skewy
- 变形(skew)实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>skew</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
margin:15% auto;
transform: skew(30deg);
}
/*动画写在主样式里,页面加载完成之后就执行*/
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/1fffea917e029bd5f6a3a48b9e50dd25.gif)
4.scale(伸缩比例)
scale
两个参数时,分别是宽度和高度的比例scale
一个参数时,是等比例缩放- 伸缩比例(scale)实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>scale</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
margin:15% auto;
transform: scale(2);
}
/*动画写在主样式里,页面加载完成之后就执行*/
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![scale实例](https://i-blog.csdnimg.cn/blog_migrate/5a1cb2be25b2d76cce989ccdd8dfe1cc.gif)
transform相关补充:
transform-orgin
:2d,3d转换中心的设置transform-style:preserve-3d;
2d转化为3d动画
二、transition(过渡动画)
1.transition相关补充
transition-property
过渡的属性transition-delay
延迟时间transition-duration
动画过渡时间transition-timing-function
过渡效果的时间曲线:linear
(匀速)、ease
(慢-快-慢)、ease-in
(开始慢)、ease-out
(结束慢)、ease-in-out
(开始、结束慢)
2.示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>transition</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
transition: all 3s linear;
}
/*transition:过渡的属性 过渡时间 延迟时间 效果曲线*/
.block:hover{
height:300px;
}
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7e1b08cb40dcbb2f56d7bde1a12703d4.gif)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>transition</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
transition: all 3s linear;
}
.block:hover{
height:300px;
width:300px;
transform: rotate(180deg);
}
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4cea031f804965d9c3a856edc26b64fe.gif)
三、animation(帧动画)
- 当在@keyframe创建动画,把它绑定到一个选择器
1.animation相关补充
animation-name
规定 @keyframes
动画的名称animation-duration
执行动画所需时间。默认是0animation-timing-function
规定动画的速度曲线 。默认是ease
animation-delay
延迟时间。默认时0animation-iteration-count
规定动画被播放的次数。默认是 1animation-direction
规定动画是否在下一周期逆向地播放。默认是 “normal
”。 :normal
(正常)、reverse
(动画反向播放)、alternate
(奇数时正向播放,偶数时反向播放)、alternate-reverse
(奇数时反向播放,偶数式正向播放)
2.示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>弹球动画</title>
<style>
.block{
width:100px;
height:100px;
border-radius: 50%;
background: linear-gradient(180deg,pink,deepskyblue);
margin: 0 auto;
animation: tanqiu 2s ease-in infinite alternate;
}
/*animation:自定义名称 动画执行时间 速度曲线 执行次数 逆向播放方法*/
@keyframes tanqiu {
/*写法1.将动画时间进行时间段划分,分别规定动画效果*/
10%{
margin-top:600px;}
40%{
margin-top:300px;
}
50%{
margin-top:600px;
}
60%{
margin-top:450px;
}
70%{
margin-top:600px;
}
80%{
margin-top:550px;
}
90%{
margin-top:600px;
}
}
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/496fedf32cc721028296d5421bdc1782.gif)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>animation</title>
<style>
.block{
width:100px;
height:100px;
background-color: aqua;
margin:15% auto;
animation:fromto 1s linear infinite alternate;
}
/*animation:自定义名称 动画执行时间 速度曲线 执行次数 逆向播放方法*/
@keyframes fromto {
/*写法2.直接规定开始和结束的状态*/
from{
transform: scale(1);}
to{
transform:scale(1.3);}
}
</style>
</head>
<body>
<div class="block"></div>
</body>
</html>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/667b480d45f351a64d310339c7824856.gif)