css-3d旋轉相冊

                                                               css-3d旋轉相冊

1、轉載地址:程序員女朋友的相冊是這樣的

2、效果

3、代碼(複製可用)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>css-3d旋轉相冊</title>
    <style>
        html{
            background:linear-gradient(#FF6666 0%,#336699 20%);/*背景漸變顏色*/
            height: 100%;
            color:#99cc33;/*文字顏色*/
        }

        /*最外層容器樣式*/
        .wrap{
            width: 200px;
            height: 200px;
            /*改變左右上下,圖片方塊移動*/
            margin: 150px auto;
            position: relative;

        }
        /*包裹所有容器樣式*/
        .cube{
            width: 200px;
            height: 200px;
            margin: 0 auto;
            transform-style: preserve-3d;
            transform: rotateX(-30deg) rotateY(-80deg);
            -webkit-animation: rotate 20s infinite;
            /*勻速*/
            animation-timing-function: linear;
        }
        @-webkit-keyframes rotate{
            from{transform: rotateX(0deg) rotateY(0deg);}
            to{transform: rotateX(360deg) rotateY(360deg);}
        }
        .cube div{
            position: absolute;
            width: 200px;
            height: 200px;
            opacity: 0.8;
            transition: all .4s;
        }
        /*定義所有圖片樣式*/
        .pic{
            width: 200px;
            height: 200px;
        }
        .cube .out_front{
            transform: rotateY(0deg) translateZ(100px);
        }
        .cube .out_back{
            transform: translateZ(-100px) rotateY(180deg);
        }
        .cube .out_left{
            transform: rotateY(90deg) translateZ(100px);
        }
        .cube .out_right{
            transform: rotateY(-90deg) translateZ(100px);
        }
        .cube .out_top{
            transform: rotateX(90deg) translateZ(100px);
        }
        .cube .out_bottom{
            transform: rotateX(-90deg) translateZ(100px);
        }
        /*定義小正方體樣式
        */
        .cube span{
            display: bloack;
            width: 100px;
            height: 100px;
            position: absolute;
            top: 50px;
            left: 50px;
        }
        .cube .in_pic{
            width: 100px;
            height: 100px;
        }
        .cube .in_front{
            transform: rotateY(0deg) translateZ(50px);
        }
        .cube .in_back{
            transform: translateZ(-50px) rotateY(180deg);
        }
        .cube .in_left{
            transform: rotateY(90deg) translateZ(50px);
        }
        .cube .in_right{
            transform: rotateY(-90deg) translateZ(50px);
        }
        .cube .in_top{
            transform: rotateX(90deg) translateZ(50px);
        }
        .cube .in_bottom{
            transform: rotateX(-90deg) translateZ(50px);
        }
        /*鼠標移入後樣式*/
        /*.cube:hover .out_front{
            transform: rotateY(0deg) translateZ(200px);
        }
        .cube:hover .out_back{
            transform: translateZ(-200px) rotateY(180deg);
        }
        .cube:hover .out_left{
            transform: rotateY(90deg) translateZ(200px);
        }
        .cube:hover .out_right{
            transform: rotateY(-90deg) translateZ(200px);
        }
        .cube:hover .out_top{
            transform: rotateX(90deg) translateZ(200px);
        }
        .cube:hover .out_bottom{
            transform: rotateX(-90deg) translateZ(200px);
        }*/
        .hovertreeinfo{text-align:center;}
        .hovertreeinfo a{color:white}
    </style>
</head>
<body>
<div class="hovertreeinfo">
    <h2>3D圖片旋轉</h2>
</div>
<!--/*外層最大容器*/-->
<div class="wrap">
    <!--	/*包裹所有元素的容器*/-->
    <div class="cube">
        <!--前面圖片 -->
        <div class="out_front">
            <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3104194953,617480653&fm=26&gp=0.jpg" class="pic" />
        </div>
        <!--後面圖片 -->
        <div class="out_back">
            <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1570190499,3408240602&fm=26&gp=0.jpg" class="pic" />
        </div>
        <!--左圖片 -->
        <div class="out_left">
            <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2113881760,2913304975&fm=26&gp=0.jpg" class="pic" />
        </div>
        <div class="out_right">
            <img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4095394213,1272226896&fm=11&gp=0.jpg" class="pic" />
        </div>
        <div class="out_top">
            <img src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2484758016,2231158131&fm=26&gp=0.jpg" class="pic" />
        </div>
        <div class="out_bottom">
            <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3576291600,3103815948&fm=11&gp=0.jpg" class="pic" />
        </div>
        <!--小正方體 -->
        <span class="in_front">
            <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3315838951,2925046183&fm=26&gp=0.jpg" class="in_pic" />
        </span>
        <span class="in_back">
            <img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2311925248,2521631346&fm=26&gp=0.jpg" class="in_pic" />
        </span>
        <span class="in_left">
            <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1629181125,3793485573&fm=26&gp=0.jpg" class="in_pic" />
        </span>
        <span class="in_right">
            <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1263550701,2004494872&fm=26&gp=0.jpg" class="in_pic" />
        </span>
        <span class="in_top">
            <img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1899402122,4230827200&fm=26&gp=0.jpg" class="in_pic" />
        </span>
        <span class="in_bottom">
            <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2011982264,1922646236&fm=26&gp=0.jpg" class="in_pic" />
        </span>
    </div>
</div>
<script>
    //每過5秒 樣式修改
    var index = 1;
    setInterval(function(){
        if(index%2==1){
            out_open();
        }else{
            out_close();
        }
        index = (index%2==0) ? 1 : 0;
    }, 5000);   //設置每5秒打開,關閉

    //設置鼠標移入打開效果
    function out_open(){
        document.getElementsByClassName('out_front')[0].style.cssText = 'transform:rotateY(0deg) translateZ(200px)';
        document.getElementsByClassName('out_back')[0].style.cssText = 'transform:translateZ(-200px) rotateY(180deg)';
        document.getElementsByClassName('out_left')[0].style.cssText = 'transform:rotateY(90deg) translateZ(200px)';
        document.getElementsByClassName('out_right')[0].style.cssText = 'transform:rotateY(-90deg) translateZ(200px)';
        document.getElementsByClassName('out_top')[0].style.cssText = 'transform:rotateX(90deg) translateZ(200px)';
        document.getElementsByClassName('out_bottom')[0].style.cssText = 'transform:rotateX(-90deg) translateZ(200px)';
    }

    //設置鼠標移出關閉效果
    function out_close() {
        document.getElementsByClassName('out_front')[0].style.cssText = 'transform:rotateY(0deg) translateZ(100px)';
        document.getElementsByClassName('out_back')[0].style.cssText = 'transform:translateZ(-100px) rotateY(180deg)';
        document.getElementsByClassName('out_left')[0].style.cssText = 'transform:rotateY(90deg) translateZ(100px)';
        document.getElementsByClassName('out_right')[0].style.cssText = 'transform:rotateY(-90deg) translateZ(100px)';
        document.getElementsByClassName('out_top')[0].style.cssText = 'transform:rotateX(90deg) translateZ(100px)';
        document.getElementsByClassName('out_bottom')[0].style.cssText = 'transform:rotateX(-90deg) translateZ(100px)';
    }
</script>
</body>
</html>

 

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