使用CSS製作簡易3D效果旋轉木馬執行個體代碼

來源:互聯網
上載者:User
最近看一下css3d的一些特性,想著也實驗學習一下,製作個小demo之類的。就練習了一下。開發一個粗糙的選擇木馬效果,

其實就是找到角度和位置,計算每根柱子的旋轉角度擺放到3d空間的置頂位置即可。然後利用css的animate屬性讓3d舞台無線旋轉,就有了一簡易的旋轉木馬效果。感興趣的可以看一下,可以把代碼中的圖片路徑改為自己的圖片地址就行了。直接可用。

代碼如下:

<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title>    <style>        .box{            width:800px;            height: 600px;            margin:0px auto;        }        .box .stage{            perspective:0px;            perspective-origin: center center;        }        .box .stage .container{            transform-style: preserve-3d;        }        .box ul,.box li{            list-style: none;            margin:0px;            padding:0px;            text-align: center;            font-weight: bold;        }        .box ul{            margin-left:200px;            width:400px;            height:400px;        }        .box li{            position: absolute;            margin-left:200px;            width:10px;            height:300px;            background: blue;            color:red;            transform-origin: 5px top;        }        .box li> .horse{            width:100px;            height:100px;            position: absolute;            top:298px;            left:-55px;            border-radius: 50px;            background-image: url("horse.jpg");            background-size: contain;        }        .box ul{            animation: run 20s linear infinite;        }        @-webkit-keyframes run {            0%{                transform: rotateY(0deg);            }            100%{                transform: rotateY(360deg);            }        }        @-webkit-keyframes horserun {            0%{                transform: translateY(0px);            }            100%{                transform: translateY(50px);            }        }    </style>    <script src="js/jquery-1.11.2.js"></script>    <script>        $(function(){            var len=$(".container>li").length;            $(".container>li").each(function(e){                var index=$(".container>li").index(this)+1;                $(this).css({                   "transform":"rotateY("+360/len * index+"deg) skew(60deg)"                });            });        })    </script></head><body><p class="box">    <p class="stage">        <ul class="container">            <li class="horse1">                <p class="horse"></p>            </li>            <li style="background: orange">                <p class="horse"></p>            </li>            <li style="background: #ffff00">                <p class="horse"></p>            </li>            <li style="background: green">                <p class="horse"></p>            </li>            <li style="background: blue">                <p class="horse"></p>            </li>            <li style="background:lightskyblue ">                <p class="horse"></p>            </li>            <li style="background: purple">                <p class="horse"></p>            </li>            <li style="background: black">                <p class="horse"></p>            </li>        </ul>    </p></p></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.