正方体旋转动画(2个小例子)

本文介绍了如何实现正方体旋转动画的两个实例。第一个例子通过组合div形成正方体,并利用旋转和平移设定3D效果。通过设置父容器的perspective属性实现立体感,调整旋转角度实现不同轴向的旋转。第二个例子则通过改变父容器的旋转,而非单独旋转每个面。为了避免面在旋转时重叠,每个面还需沿自身前方适当位移。文章附带了实际效果展示。
摘要由CSDN通过智能技术生成

正方体旋转动画

设置原理:
第一个例子: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(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值