一款利用html5和css3实现的3D立方体旋转效果教程
.top{top:-152px;transform: rotateX(-90deg);transform-origin: bottom;background: url(../images/photo3.jpg);background-size:100% 100%;} .bottom{top:152px;transform: rotateX(90deg);transform-origin: top;background: url(../images/photo2.jpg);background-size:100% 100%;} .front{transform: translateZ(152px);z-index:2;background: url(../images/photo1.jpg);background-size:100% 100%;} .back{z-index:1;background: url(../images/photo.jpg);background-size:100% 100%;} .container:hover{transform: rotateY(360deg)} </style> </head> <body> <div class="stage"> <div class="container"> <div class="side front"></div> <div class="side back"></div> <div class="side left"></div> <div class="side right"></div> <div class="side top"></div> <div class="side bottom"></div> </div> </div> </body> </html> 但是这个在旋转时,有一个问题,不该看到的平面也会被看到: 相反,如果通过另一种方式来实现,则不会有这个问题。不修改容器的旋转中心,通过将后面,上下左右面沿着Z轴向后平移宽度的一般,然后再将前面向前移动宽度的一般,那么旋转中心就是盒子的中心。 XML/HTML Code复制内容到剪贴板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .stage{perspective: 800px;} .container{width: 150px;height:150px;margin: 200px auto; position: relative; transform-style: preserve-3d;height:200px;transition:5s;} (编辑:焦作站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |