旋转的立方体

最近总是纠结去哪里吃饭,所以就想着做了一个色子,也算是朝花夕拾了,最后做出来的是一个旋转的立方体,整体美感还好:实现了永久旋转,悬浮停止和突出及一个分散的效果:以下是代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>立方体旋转</title> <style type="text/css"> *{ margin:0 auto; padding:0; } @keyframes rotate{ 0%{ transform:rotateX(0deg) rotateY(0deg); } 100%{ transform:rotateX(360deg) rotateY(360deg); } } html{ height:100%; } .wrap{ width: 200px; height: 200px; margin-top:200px; perspective: 1000px; } .cube{ width:200px; height:200px; position:relative; color:#fff; font-size:36px; text-align:center; line-height:200px; transform-style:preserve-3d; transform:rotateX(-30deg) rotateY(-70deg); animation:rotate 20s infinite linear;
} .cube > div{ width:100%; height:100%; border:1px solid #fff; position:absolute; background:rgba(0,0,0,.5); opacity:.5; transition:transform 0.5s ease-out; } .cube > div >img{ width: 200px; height: 200px; } .cube .out-front{ transform: translateZ(100px); } .cube .out-back{ transform: translateZ(-100px) rotateY(180deg); } .cube .out-left{ transform: translateX(-100px) rotateY(-90deg); } .cube .out-right{ transform: translateX(100px) rotateY(90deg); } .cube .out-top{ transform: translateY(-100px) rotateX(90deg); } .cube .out-bottom{ transform: translateY(100px) rotateX(-90deg); } .cube .in-front{ transform: translateZ(50px); } .cube .in-back{ transform: translateZ(-50px) rotateY(180deg); } .cube .in-left{ transform: translateX(-50px) rotateY(-90deg); } .cube .in-right{ transform: translateX(50px) rotateY(90deg); } .cube .in-top{ transform: translateY(-50px) rotateX(90deg); } .cube .in-bottom{ transform: translateY(50px) rotateX(-90deg); } .wrap:hover .out-front{ transform: translateZ(200px); } .wrap:hover .out-back{ transform: translateZ(-200px) rotateY(180deg); } .wrap:hover .out-left{ transform: translateX(-200px) rotateY(-90deg); } .wrap:hover .out-right{ transform: translateX(200px) rotateY(90deg); } .wrap:hover .out-top{ transform: translateY(-200px) rotateX(90deg); } .wrap:hover .out-bottom{ transform: translateY(200px) rotateX(-90deg); } </style> </head> <body> <div class="wrap"> <div class="cube cubeX"> <div class="out-front"><img src="./img/1.jpg" alt=""></div> <div class="out-back">kim</div> <div class="out-left"><img src="./img/3.jpg" alt=""></div> <div class="out-right"><img src="./img/4.jpg" alt=""></div> <div class="out-top"><img src="./img/5.jpg" alt=""></div> <div class="out-bottom"><img src="./img/6.jpg" alt=""></div> </div> </div> </body> <script type="text/javascript" src="jquery-1.8.1.js"></script> <script> $(".cube > div").mouseover(function(){ $(".cube").css({"animation-play-state":"","animation-duration":"7s"}); $(this).css("opacity",1); }).mouseout(function(){ $(".cube").css({"animation-play-state":"","animation-duration":"20s"}); $(this).css("opacity",.5); }) </script> </html>

以上利用了transform属性和旋转的属性,实现了立方体的拼接,旋转。整体代码巨简单,jq因为是本地引入,具体路径与版本需看自己的情况。

  

 

posted @ 2018-01-16 11:46  kimsaerono  阅读(265)  评论(0编辑  收藏  举报