欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

用CSS3实现一个魔方转动动画

程序员文章站 2022-03-28 20:21:39
...
*{
    margin: 0;
    padding: 0;
}

:root, body{
    height: 100%;
}

@keyframes round{
    0%{
        transform: rotateY(0deg) rotateX(0deg);
    }
    50%{
        transform: rotateY(360deg) rotateX(180deg);
    }
    100%{
        transform: rotateY(360deg) rotateX(360deg);
    }
}


body{
    perspective: 2000px;
    transform-style: preserve-3d;
}

div.wrapper{
    width: 400px;
    height: 400px;
    position: absolute;
    left: calc(50% - 200px);
    top: calc(50% - 200px);
    transform-style: preserve-3d;
    animation: round 10s linear infinite;
}

.content1,
.content2,
.content3,
.content4,
.content5,
.content6{
    position: absolute;
    height: 400px;
    width: 400px;
    line-height: 400px;
    text-align: center;
    color: #000;
    font-size: 20px;
}

.content1{
    background-color: #FFF68F;
    transform: translateZ(-200px);
}
.content6{
    background-color: #FF4500;
    transform: translateZ(200px);
}

.content2{
    background-color: #D15FEE;
    transform: translateX(200px) rotateY(90deg);
}
.content5{
    background-color: #008c8c;
    transform: translateX(-200px) rotateY(-90deg);
}

.content3{
    background-color: #8B2323;
    transform: translateY(200px) rotateX(-90deg);
}
.content4{
    background-color: #87CEEB;
    transform: translateY(-200px) rotateX(90deg);
}
<div class="wrapper">
        <div class="content1">1</div>
        <div class="content2">2</div>
        <div class="content3">3</div>
        <div class="content4">4</div>
        <div class="content5">5</div>
        <div class="content6">6</div>
</div>

效果如下
用CSS3实现一个魔方转动动画

相关标签: css3 css