正方体旋转动画
设置原理:
第一个例子:1.用div先写出六个面
2.通过旋转、平移方式将六个面组成正方体
3.将父容器设成perspective透视,无透视,不3d
4.设置立体旋转方向(要搞清楚绕着哪个轴旋转)
此处旋转角度为90deg
第二个例子:
立体设置同上,主要是把父容器旋转,而不是分别将面旋转。
另外:当面进行旋转的时候,他们会挤在一起,所以需要让每个面都要向他自身的前面走几步(假设为r,计算公式为 如下图)
将容器设为透视
body{
perspective: 1200px;
transform-style: preserve-3d;
}
.box{
width: 200px;
height: 200px;
position: absolute;
top: 300px;
left: 500px;
opacity: 0.5;
}
//分别设置六个面,并将其旋转,平移
.red{
/* 前 */
background-color: red;
transform: translate3d(0px,0px,100px);
animation: box_red 2s linear infinite;
}
.yellow{
/* 上 */
background-color: yellow;
transform: translate3d(0px,0px,100px);
animation: box_yellow 2s linear infinite;
}
.blue{
/* 左 */
background-color: blue;
/* transform: rotateY(90deg) translate3d(0px,0px,-100px); */
transform:translate3d(0px,0px,-100px);
animation: box_blue 2s linear infinite;
}
.green{
/* 右 */
background-color: green;
/* transform: rotateY(-90deg) translate3d(0px,0px,-100px); */
transform: translate3d(0px,0px,-100px);
animation: box_green 2s linear infinite;
}
.black{
/* 下 */
background-color: black;
/* transform: rotateX(-90deg) translate3d(0px,0px,100px); */
transform: translate3d(