纯css实现3D动画

it2022-05-05  96

    css动画的某些属性可以实现非常炫酷的3D效果,贴出一个例子,可直接看到效果,用到了css的3D转换和动画。

    

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /> <title></title><base target="_blank" /> </head> <style type="text/css"> body { background:url(img/low_contrast_linen.png) repeat; } /*最外层容器样式*/ .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; transition: all .4s; } /*定义所有图片样式*/ .pic{ width: 200px; height: 200px; } .out_front{ transform: rotateY(0deg) translateZ(100px); } .out_back{ transform: translateZ(-100px) rotateY(180deg); } .out_left{ transform: rotateY(90deg) translateZ(100px); } .out_right{ transform: rotateY(-90deg) translateZ(100px); } .out_top{ transform: rotateX(90deg) translateZ(100px); } .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); } </style> <body> <div class="wrap"> <div class="cube"> <div class="out_front"> <img src="https://hbimg.b0.upaiyun.com/7df15fc52a6973ba722c4cedc25d8a44062f05b72c425-b4WxhD_fw658" class="pic" /> </div> <div class="out_back"> <img src="https://hbimg.b0.upaiyun.com/66782330812a6a8b53dee4f4233d9c872ed865a1ce6a-cNnuer_fw658" class="pic" /> </div> <div class="out_left"> <img src="https://hbimg.b0.upaiyun.com/6d6085a53663cb9854cda9a5e702b55a4161b8f3195f6-LIGGfb_fw658" class="pic" /> </div> <div class="out_right"> <img src="https://hbimg.b0.upaiyun.com/8781d90bda5e7faa2ad89e814444dc6db2470ce53601f-ZRMABG_fw658" class="pic" /> </div> <div class="out_top"> <img src="https://hbimg.b0.upaiyun.com/b2f70724c8d56e8231cf9e883f97a6873911ec153642-EgHjI1_fw658" class="pic" /> </div> <div class="out_bottom"> <img src="https://hbimg.b0.upaiyun.com/835671d1cf35df3cecd79e3f9d92d98abdec8fc925b33-lOHUe7_fw658" class="pic" /> </div> <span class="in_front"> <img src="https://hbimg.b0.upaiyun.com/b2f3af8a767eeef20b1338f8b0ee7fdbfe07300215300-ytBex2_fw658" class="in_pic" /> </span> <span class="in_back"> <img src="https://hbimg.b0.upaiyun.com/58722241569fe3d1adfe5b4da228d9d5da01d85968c5-byY65r_fw658" class="in_pic" /> </span> <span class="in_left"> <img src="https://hbimg.b0.upaiyun.com/bcfccbee05e34b8f8e0dc66e1238ccc36ecdee5cc8a3-FrNbfN_fw658" class="in_pic" /> </span> <span class="in_right"> <img src="https://hbimg.b0.upaiyun.com/d31aa1e53f63add54e15a07a40c2ccf5cf2572a0d1b0-GYI7td_fw658" class="in_pic" /> </span> <span class="in_top"> <img src="https://hbimg.b0.upaiyun.com/dbeae729893b7bb3be7ed8e72787f2c4f5b33a333824-PqcOAL_fw658" class="in_pic" /> </span> <span class="in_bottom"> <img src="https://hbimg.b0.upaiyun.com/1d410387a18896078ce7cb9b29888fd7f5357ca5ef04-J2SQLl_fw658" class="in_pic" /> </span> </div> </div> </body> </html>

   

转载于:https://www.cnblogs.com/chaimengchen/p/8426978.html

相关资源:纯CSS3实现3D立方体旋转动画.zip

最新回复(0)