溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何解決CSS3旋轉立方體問題

發布時間:2021-03-22 12:49:07 來源:億速云 閱讀:242 作者:小新 欄目:web開發

這篇文章主要介紹如何解決CSS3旋轉立方體問題,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

3D坐標概念

如何解決CSS3旋轉立方體問題 

  • 當元素進行旋轉時,他的坐標軸也跟著他進行旋轉

  • 注意-y方向問題

旋轉立方體的效果

如何解決CSS3旋轉立方體問題 

分析

  •  一個容器包含6個div

  • position:absolute 之后6個面完全重合

  • 通過trandform:rotateX/Y/Z(),translateX/Y/Z()調整到相應位置

  • 添加transition動畫效果

  • 注意這里面的旋轉是繞著他的中心線進行旋轉的所以唯一100px

  • 他在旋轉時,他的坐標軸也是跟著他進行旋轉的(這很重要)

代碼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;

        }
        body{
            perspective: 800px;
            background: #000000;
        }
        #container{
            height: 200px;
            width: 200px;
            margin: 100px auto 0;
            position: relative;
            transform-style: preserve-3d;
            animation: move 1s ease infinite;

        }
        @keyframes move{
            from{
                transform: rotateY(0deg) rotateZ(0deg);
            }
            to{
                transform: rotateY(360deg) rotateZ(360deg);
            }
            
        }
        #container>div{
            height: 100%;
            width: 100%;
            border-radius: 5px;
            background: rgba(255,255,255,0.5);
            position: absolute;
            left: 0px;
            right: 0px;
            text-align: center;
            line-height: 200px;
            font-size: 30px;
        }
        #one{
            transform:rotateX(-90deg) translateZ(100px);
        }
        #two{
            transform:translateZ(100px) ;
        }
        #three{
            transform: rotateY(-90deg) translateZ(100px);
        }
        #four{
            transform: rotateY(-180deg) translateZ(100px);
        }
        #five{
            transform: rotateY(90deg) translateZ(100px);
        }
        #six{
            transform: translateZ(-100px);
        }
        
    </style>
</head>
<body>
    <div id="container">
        <div id="one">1</div>
        <div id="two">2</div>
        <div id="three">3</div>
        <div id="four">4</div>
        <div id="five">5</div>
        <div id="six">6</div>
    </div>
</body>
</html>

以上是“如何解決CSS3旋轉立方體問題”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女