前端构建3D建模知识(css,html)
Perspective
perspective设置的大小不同
perspective-origin代表了X和Y轴,而perspective代表Z轴。
构建一个3D缺少不了3个要素:
- 摄像机(Camera)
- 舞台(stage)
- 物体(Object)本身。
Transform指3D变换
- 旋转(Rotate)可以绕X、Y、Z三个轴旋转对应rotateX、rotateY、rotateZ三个方法
- 平移(Translate)同样,坐标平移Translate也有tranlateX、tranlateY、translateZ三个方法
- 为了让元素都是立体元素,需要在这个立体空间上设置tranform-style的值为preserve-3d。
Transition的意思是过渡:做一些动画效果的时候会用到它!
- transition-property(规定设置过渡效果的 CSS 属性的名称)
- transition-duration (规定完成过渡效果需要多少秒或毫秒)
- transition-timing-function(规定速度效果的速度曲线)
- transition-delay (定义过渡效果何时开始)
html
<div class="camera">
<div class="stage tst">
<div class="cube up">up</div>
<div class="cube down">down</div>
<div class="cube left">left</div>
<div class="cube right">right</div>
<div class="cube front">front</div>
<div class="cube back">back</div>
</div>
</div>
css
.camera {
width: 400px;
height: 400px;
perspective: 1000px;
perspective-origin: center center;
}
.stage {
width:100%;
height:100%;
border:1px dashed #000;
transform: rotateY(0deg) rotateX(0deg);
transform-style:preserve-3d;
}
.cube {
position: absolute;
left: 75px;
top: 100px;
margin-left: 30px;
width: 200px;
height: 200px;
color: white;
background-color: rgba(255, 85, 85, 1);
}
.up {
background-color: rgba(48, 44, 102,1);
transform: rotateX(90deg) translateZ(100px);
}
.down {
transform: rotateX(-90deg) translateZ(100px);
}
.left {
background-color: rgba(254, 56, 69,1);
transform: rotateY(-90deg) translateZ(100px);
}
.right {
transform: rotateY(90deg) translateZ(100px);
}
.front {
background-color: rgba(100, 225, 180,1);
transform: translateZ(100px);
}
.back {
transform: rotateY(180deg) translateZ(100px);
}
.tst {
transition: transform 2s linear 1s;
}
效果图
详细原文
https://www.imooc.com/article/12670
扩展原文
http://web.jobbole.com/86929/