舞台层
- 景深层 perspective: 1600px;
- 形变中心点perspective-origin: 0px 0px;
- 形变中心点transform-origin: center center;
3d中心层
就是围绕运动的层
下面用几个例子来介绍3d动画
例1正方体
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>魔方</title>
<style type="text/css">
body{
background: black;
}
.pp{
perspective: 1600px;
}
.wrap{
transform-style: preserve-3d;
transform: rotateX(30deg) rotateY(30deg);
width: 200px;
height: 200px;
margin: 200px auto;
position: relative;
animation: donghua 2s linear infinite;
}
@keyframes donghua{
0%{
transform: rotateX(30deg) rotateY(30deg);
}
100%{
transform: rotateX(360deg) rotateY(360deg);
}
}
.wrap div{
width: 210px;
height: 210px;
position: absolute;
border: 1px solid yellow;
background-color: black;
box-shadow: 0 0 20px 2px yellow;
color: white;
font-size: 50px;
text-align: center;
line-height: 210px;
text-shadow: 5px 5px 20px red ;
opacity: 0.5;
}
.box1{
background: red;
transform: translateZ(105px);
}
.box2{
background: orange;
transform: translateZ(-105px);
}
.box3{
background: blue;
transform: translateX(105px)rotateY(90deg);
}
.box4{
background: green;
transform: translateX(-105px)rotateY(90deg);
}
.box5{
background: cyan;
transform: translateY(-105px)rotateX(90deg);
}
.box6{
background: purple;
transform: translateY(105px)rotateX(90deg);
}
.box7{
background: red;
transform: translateZ(35px);
}
.box8{
background: orange;
transform: translateZ(-35px);
}
.box9{
background: blue;
transform: translateX(35px)rotateY(90deg);
}
.box10{
background: green;
transform: translateX(-35px)rotateY(90deg);
}
.box11{
background: cyan;
transform: translateY(-35px)rotateX(90deg);
}
.box12{
background: purple;
transform: translateY(35px)rotateX(90deg);
}
</style>
</head>
<body>
<div class="pp">
<div class="wrap">
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
<div class="box5">5</div>
<div class="box6">6</div>
<div class="box7">7</div>
<div class="box8">8</div>
<div class="box9">9</div>
<div class="box10">10</div>
<div class="box11">11</div>
<div class="box12">12</div>
</div>
</div>
</body>
</html>
代码运行图
例2 圈图
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>圈</title>
<style type="text/css">
body{
background: gray;
}
.box{
perspective: 2600px;
}
.wrap{
width: 200px;
height: 200px;
border: 1px solid red;
transform-style: preserve-3d;
position: relative;
margin: 300px auto;
transform: rotateX(-10deg)rotateY(10deg);
animation: donghua 30s linear infinite;
}
@keyframes donghua{
0%{
transform: rotateX(-10deg)rotateY(10deg);
}
100%{
transform: rotateX(-10deg)rotateY(3600deg);
}
}
.wrap:hover{
animation-play-state: paused;
}
.wrap div{
width: 200px;
height: 200px;
position: absolute;
}
.box1{
background-image: url('1.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: red;
transform: rotateY(360deg)translateZ(500px);
}
.box2{
background-image: url('2.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: yellow;
transform: rotateY(30deg)translateZ(500px);
}
.box3{
background-image: url('3.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: blue;
transform: rotateY(60deg)translateZ(500px);
}
.box4{
background-image: url('4.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: green;
transform: rotateY(90deg)translateZ(500px);
}
.box5{
background-image: url('5.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: cyan;
transform: rotateY(120deg)translateZ(500px);
}
.box6{
background-image: url('6.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: purple;
transform: rotateY(150deg)translateZ(500px);
}
.box7{
background-image: url('7.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: greenyellow;
transform: rotateY(180deg)translateZ(500px);
}
.box8{
background-image: url('8.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: pink;
transform: rotateY(210deg)translateZ(500px);
}
.box9{
background-image: url('9.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: orange;
transform: rotateY(240deg)translateZ(500px);
}
.box10{
background-image: url('10.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: gray;
transform: rotateY(270deg)translateZ(500px);
}
.box11{
background-image: url('11.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color: seagreen;
transform: rotateY(300deg)translateZ(500px);
}
.box12{
background-image: url('12.jpg');
background-repeat:no-repeat;
background-size: cover;
background-color:purple;
transform: rotateY(330deg)translateZ(500px);
}
</style>
</head>
<body>
<div class="box">
<div class="wrap">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
<div class="box6"></div>
<div class="box7"></div>
<div class="box8"></div>
<div class="box9"></div>
<div class="box10"></div>
<div class="box11"></div>
<div class="box12"></div>
</div>
</div>
</body>
</html>
运行结果:
例3 旋转链
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>旋转多圈</title>
<style type="text/css">
body{
background: skyblue;
}
.box{
perspective: 1600px;
}
.wrap{
width: 50px;
height: 50px;
border: 1px solid red;
transform-style: preserve-3d;
position: relative;
margin: 400px auto;
transform: rotateX(-10deg)rotateY(10deg);
animation: donghua 10s linear infinite ;
perspective-origin: 0 0 ;
}
.wrap:hover{
animation-play-state: paused;
}
@keyframes donghua{
0%{
transform: rotateX(-10deg)rotateY(10deg);
}
100%{
transform: rotateX(-10deg)rotateY(3600deg);
}
}
.wrap div{
width: 50px;
height: 50px;
position: absolute;
font-size: 30px;
color: white;
line-height: 50px;
text-align: center;
}
.box1{
background-color: red;
transform: rotateY(360deg)translateZ(200px);
}
.box2{
background-color: yellow;
transform: rotateY(30deg)translateZ(200px)translateY(20px);
}
.box3{
background-color: blue;
transform: rotateY(60deg)translateZ(200px)translateY(40px);
}
.box4{
background-color: green;
transform: rotateY(90deg)translateZ(200px)translateY(60px);
}
.box5{
background-color: cyan;
transform: rotateY(120deg)translateZ(200px)translateY(80px);
}
.box6{
background-color: purple;
transform: rotateY(150deg)translateZ(200px)translateY(100px);
}
.box7{
background-color: greenyellow;
transform: rotateY(180deg)translateZ(200px)translateY(120px);
}
.box8{
background-color: pink;
transform: rotateY(210deg)translateZ(200px)translateY(140px);
}
.box9{
background-color: orange;
transform: rotateY(240deg)translateZ(200px)translateY(160px);
}
.box10{
background-color: gray;
transform: rotateY(270deg)translateZ(200px)translateY(180px);
}
.box11{
background-color: seagreen;
transform: rotateY(300deg)translateZ(200px)translateY(200px);
}
.box12{
background-color:purple;
transform: rotateY(330deg)translateZ(200px)translateY(220px);
}
.box13{
background-color: red;
transform: rotateY(360deg)translateZ(200px)translateY(240px);
}
.box14{
background-color: yellow;
transform: rotateY(30deg)translateZ(200px)translateY(260px);
}
.box15{
background-color: blue;
transform: rotateY(60deg)translateZ(200px)translateY(280px);
}
.box16{
background-color: green;
transform: rotateY(90deg)translateZ(200px)translateY(300px);
}
.box17{
background-color: cyan;
transform: rotateY(120deg)translateZ(200px)translateY(320px);
}
.box18{
background-color: purple;
transform: rotateY(150deg)translateZ(200px)translateY(340px);
}
.box19{
background-color: greenyellow;
transform: rotateY(180deg)translateZ(200px)translateY(360px);
}
.box20{
background-color: pink;
transform: rotateY(210deg)translateZ(200px)translateY(-340px);
}
.box21{
background-color: orange;
transform: rotateY(240deg)translateZ(200px)translateY(-320px);
}
.box22{
background-color: gray;
transform: rotateY(270deg)translateZ(200px)translateY(-300px);
}
.box23{
background-color: seagreen;
transform: rotateY(300deg)translateZ(200px)translateY(-280px);
}
.box24{
background-color:purple;
transform: rotateY(330deg)translateZ(200px)translateY(-260px);
}
.box25{
background-color: red;
transform: rotateY(360deg)translateZ(200px)translateY(-240px);
}
.box26{
background-color: yellow;
transform: rotateY(30deg)translateZ(200px)translateY(-220px);
}
.box27{
background-color: blue;
transform: rotateY(60deg)translateZ(200px)translateY(-200px);
}
.box28{
background-color: green;
transform: rotateY(90deg)translateZ(200px)translateY(-180px);
}
.box29{
background-color: cyan;
transform: rotateY(120deg)translateZ(200px)translateY(-160px);
}
.box30{
background-color: purple;
transform: rotateY(150deg)translateZ(200px)translateY(-140px);
}
.box31{
background-color: greenyellow;
transform: rotateY(180deg)translateZ(200px)translateY(-120px);
}
.box32{
background-color: pink;
transform: rotateY(210deg)translateZ(200px)translateY(-100px);
}
.box33{
background-color: orange;
transform: rotateY(240deg)translateZ(200px)translateY(-80px);
}
.box34{
background-color: gray;
transform: rotateY(270deg)translateZ(200px)translateY(-60px);
}
.box35{
background-color: seagreen;
transform: rotateY(300deg)translateZ(200px)translateY(-40px);
}
.box36{
background-color:purple;
transform: rotateY(330deg)translateZ(200px)translateY(-20px);
}
</style>
</head>
<body>
<div class="box">
<div class="wrap">
<div class="box1">活</div>
<div class="box2">半</div>
<div class="box3">步</div>
<div class="box4">你</div>
<div class="box5">若</div>
<div class="box6">平</div>
<div class="box7">凡</div>
<div class="box8">就</div>
<div class="box9">随</div>
<div class="box10">时</div>
<div class="box11">光</div>
<div class="box12">一</div>
<div class="box13">起</div>
<div class="box14">平</div>
<div class="box15">凡</div>
<div class="box16">各</div>
<div class="box17">自</div>
<div class="box18">安</div>
<div class="box19">好</div>
<div class="box20">你</div>
<div class="box21">若</div>
<div class="box22">幸</div>
<div class="box23">福</div>
<div class="box24">,</div>
<div class="box25">便</div>
<div class="box26">飞</div>
<div class="box27">到</div>
<div class="box28">天</div>
<div class="box29">边</div>
<div class="box30">不</div>
<div class="box31">再</div>
<div class="box32">踏</div>
<div class="box33">足</div>
<div class="box34">我</div>
<div class="box35">的</div>
<div class="box36">生</div>
</div>
</div>
</body>
</html>
运行结果:
通过这些例子估计也弄懂了3d效果了,由于是动画,现又不支持动画截图,如果想看动画效果的话,自己复制代码可以看到。有关3d效果就到这里了。