css3动画
transform,animation
图片
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
padding: 0px;
margin: 0px;
}
body{
max-width: 100%;
min-width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-size:100% 100%;
position: absolute;
margin-left: auto;
margin-right: auto;
}
li{
list-style:none;
}
.box{
width:200px;
height:200px;
/* background-color: red; */
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
position: absolute;
margin-left: 42%;
margin-top: 22%;
-webkit-transform-style:preserve-3d;
-webkit-transform:rotateX(13deg);
-webkit-animation:move 5s linear infinite;
}
.minbox{
/* background-color: #000; */
width:100px;
height:100px;
position: absolute;
left:50px;
top:30px;
-webkit-transform-style:preserve-3d;
}
.minbox li{
/* background-color: green; */
width:100px;
height:100px;
position: absolute;
left: 0px;
top: 0px;
}
.minbox li:nth-child(1){
background-color: hotpink;
-webkit-transform:translateZ(50px)
}
.minbox li:nth-child(2){
background-color: rgb(191, 160, 231);
-webkit-transform:rotateX(180deg) translateZ(50px);
}
.minbox li:nth-child(3){
background-color: goldenrod;
-webkit-transform:rotateX(-90deg) translateZ(50px);
}
.minbox li:nth-child(4){
background-color: rgb(125, 205, 241);
-webkit-transform:rotateX(90deg) translateZ(50px);
}
.minbox li:nth-child(5){
background-color: rgb(126, 235, 99);
-webkit-transform:rotateY(90deg) translateZ(50px)
}
.minbox li:nth-child(6){
background-color: rgb(109, 57, 230);
-webkit-transform:rotateY(-90deg) translateZ(50px)
}
@keyframes move{
0%{
-webkit-transform: rotateX(13deg) rotateY(0deg);
}
100%{
-webkit-transform:rotateX(13deg) rotateY(360deg);
}
}
</style>
</head>
<body>
<div class="box">
<ul class="minbox">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
transform属性:
2D位移
- translate(x,y):基于原来的位置,沿X轴平移,长度为x,沿2轴平移,长度为y transform:translate(x,y);
- translateX(x):基于原来的位置,沿X轴平移,长度为x transform:translateX(x);
- translateY(y): 基于原来的位置,沿Y轴平移,长度为y transform:translateY(y);
3D位移
- translate3d(x,y,z):基于原来的位置,沿X轴平移,长度为x,沿Y轴平移,长度为y,沿Z轴平移,长度为z transform:translate3d(x,y,z);
- translateZ(z): 基于原来的位置,沿Z轴平移,长度为z transform:translateZ(z);
2D缩放转换
- scale(x,y): 基于原来的位置进行伸缩变换,其中x代表沿X轴的伸缩倍数,y代表沿Y轴的伸缩倍数 transform:scale(x,y);
- scaleX(x):基于原来的位置进行伸缩变换,其中x代表沿X轴的伸缩倍数 transform:scale(x);
- scaleY(y):基于原来的位置进行伸缩变换,其中y代表沿Y轴的伸缩倍数 transform:scale(y);
3D缩放转换
-
scale3d(x,y,z): 基于原来的位置进行伸缩变换,其中x代表沿X轴的伸缩倍数,y代表沿Y轴的伸缩倍数,z代表沿Z轴的伸缩倍数 transform:scale3d(x,y,z);
-
scaleZ(z):基于原来的位置进行伸缩变换,其中z代表沿Z轴的伸缩倍数 transform:scaleZ(z);
2D旋转
-
rotate(angle): 以图形的几何中心点为旋转中心,顺时针旋转角度为angle transform:rotate(angle);
-
rotateX(x): 绕X轴方向旋转,顺时针旋转角度为angle transform:rotateX(x);
-
rotateZ(z):绕Y轴方向旋转,顺时针旋转角度为angle transform:rotateZ(z);
3D旋转
1.rotate3d(x,y,z,angle):
同时绕X,Y,Z轴三个方向旋转,顺时针旋转角度为angle transform:rotate3d(x,y,z,angle);
2.rotateZ(z): 绕Z轴方向旋转,顺时针旋转角度为angle transform:rotateZ(z);