css3動畫-正方體

css屬性

  • animation 關鍵幀
  • opacity 透明度
  • transform 動畫
  • transform-style: preserve-3d; /* 重點:保留子元素的3d效果*/
  • perspective: 1000px; /*設置透視點*/

code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            perspective: 1000px; /*設置透視點*/
        }
        .img-box{
            width: 300px;
            height: 300px;
            margin: 100px auto;
            transform-style: preserve-3d; /* 重點:保留子元素的3d效果*/
            /* transform: rotate3d(0,0,0, 360deg); 3d旋轉根據點-點向量 */

            /* 設置關鍵幀 */
            animation-name: donghua; /*名字*/
            animation-duration: 5s; /*動畫時間*/
            animation-iteration-count: infinite; /*設置動畫無限播放*/        
        }
        @keyframes donghua{
            from {
                transform: rotate3d(0,0,0, 0deg);  /*初始動畫*/
            }
            to {
                transform: rotate3d(1,1,1, 720deg);
            }
        }
        .front{
            background-image: url(img/img1.jpg);
            background-size: 100% 100%;
            height: inherit;
            width: inherit;
            opacity: 0.3;
            transform: translateZ(140px);
            position: absolute;
        }
        .back{
            background-image: url(img/img2.jpg);
            background-size: 100% 100%;
            height: inherit;
            width: inherit;
            position: absolute;
            opacity: 0.3;
            transform: translateZ(-145px);
        }
        .left{
            background-image: url(img/img3.jpg);
            background-size: 100% 100%;
            height: inherit;
            width: inherit;
            position: absolute;
            opacity: 0.3;
            transform: rotateY(-90deg) translateZ(148px);
        }
        .right{
            background-image: url(img/img4.jpg);
            background-size: 100% 100%;
            height: inherit;
            width: inherit;
            position: absolute;
            opacity: 0.3;
            transform: rotateY(90deg) translateZ(148px);
        }
        .top{
            background-image: url(img/img5.jpg);
            background-size: 100% 100%;
            height: inherit;
            width: inherit;
            position: absolute;
            opacity: 0.3;
            transform: rotateX(-90deg) translateZ(-150px);
        }
        .bottom{
            background-image: url(img/img6.jpg);
            background-size: 100% 100%;
            height: inherit;
            width: inherit;
            position: absolute;
            opacity: 0.3;
            transform: rotateX(90deg) translateZ(-150px);
        }
    </style>
</head>
<body>
    <div class="img-box">
        <div class="front"></div>
        <div class="back"></div>
        <div class="left"></div>
        <div class="right"></div>
        <div class="top"></div>
        <div class="bottom"></div>
    </div>
    
</body>
</html>

效果

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章