時(shí)間:2023-09-11 17:36:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-09-11 17:36:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)
CSS3制作3D頁(yè)面:CSS3新增了幾個(gè)有關(guān)3D轉(zhuǎn)換屬性,本文主要介紹下CSS3的一些屬性變換,以及一些酷炫的3D動(dòng)效如何實(shí)現(xiàn).transform
: CSS3中2D、3D變換屬性。<!DOCTYPE html><html> <head> <meta charset=utf-8> <title>正方體拆解</title> <link rel="stylesheet" href="./box.csss" type="text/css"> </head> <body> <div class="container-box"> <div class="box-front">前面</div> <div class="box-after">后面</div> <div class="box-left">左面</div> <div class="box-right">右面</div> <div class="box-up">上面</div> <div class="box-down">下面</div> </div> </body></html>
box.css.container-box{ position:relative; width:600px; height: 600px; perspective: none; perspective-origin: center; transform-style: preserve-3d; background-color: #edf9fa;}.container-box > div{ position:absolute; left: 200px; top: 200px; width:200px; height:200px; line-height:200px; text-align:center; }.container-box > .box-front{ background-color:#fffeee}.container-box > .box-after{ background-color:#92ffc8}.container-box > .box-left{ background-color:#0316ff}.container-box > .box-right{ background-color:#03dbff}.container-box > .box-up{ background-color:#ffbe03}.container-box > .box-down{ background-color:#ff3e03}
.container-box{ position:relative; width:600px; height: 600px; perspective: none; perspective-origin: center; transform-style: preserve-3d; background-color: #edf9fa;}.container-box > div{ position:absolute; left: 200px; top: 200px; width:200px; height:200px; line-height:200px; text-align:center; }.container-box > .box-front{ background-color:#fffeee; transform: translateZ(200px);}.container-box > .box-after{ background-color:#92ffc8; transform: translateZ(0);}.container-box > .box-left{ background-color:#0316ff}.container-box > .box-right{ background-color:#03dbff}.container-box > .box-up{ background-color:#ffbe03}.container-box > .box-down{ background-color:#ff3e03}
.container-box{ position:relative; width:600px; height: 600px; perspective: none; perspective-origin: center; transform-style: preserve-3d; background-color: #edf9fa;}.container-box > div{ position:absolute; left: 200px; top: 200px; width:200px; height:200px; line-height:200px; text-align:center; }.container-box > .box-front{ background-color:#fffeee; transform: translateZ(200px);}.container-box > .box-after{ background-color:#92ffc8; transform: translateZ(0);}.container-box > .box-left{ background-color:#0316ff; transform: translateX(-100px) translateZ(100px) rotateY(-90deg); }.container-box > .box-right{ background-color:#03dbff; transform: translateX(100px) translateZ(100px) rotateY(90deg);}.container-box > .box-up{ background-color:#ffbe03;}.container-box > .box-down{ background-color:#ff3e03;}
.container-box { transform: rotateX(30deg) rotateY(30deg);}.container-box > .box-up{ display:none;}.container-box > .box-down{ display:none;}
.container-box{ position:relative; width:600px; height: 600px; perspective: none; perspective-origin: center; transform-style: preserve-3d; background-color: #edf9fa; transform: rotateX(30deg) rotateY(30deg);}.container-box > div{ position:absolute; left: 200px; top: 200px; width:200px; height:200px; line-height:200px; text-align:center; }.container-box > .box-front{ background-color:#fffeee; transform: translateZ(200px);}.container-box > .box-after{ background-color:#92ffc8; transform: translateZ(0);}.container-box > .box-left{ background-color:#0316ff; transform: translateX(-100px) translateZ(100px) rotateY(-90deg); }.container-box > .box-right{ background-color:#03dbff; transform: translateX(100px) translateZ(100px) rotateY(90deg);}.container-box > .box-up{ background-color:#ffbe03; transform: translateY(-100px) translateZ(100px) rotateX(90deg);}.container-box > .box-down{ background-color:#ff3e03; transform: translateY(100px) translateZ(100px) rotateX(-90deg);}
<!DOCTYPE html><html> <head> <meta charset=utf-8> <title>正方體拆解</title> <style> .container-box{ position:relative; width:600px; height: 600px; perspective: none; perspective-origin: center; transform-style: preserve-3d; transform-origin: center center 100px; } .container-box > div{ position:absolute; left: 50%; top: 50%; margin-left:-100px; margin-top:-100px; width:200px; height:200px; line-height:200px; text-align:center; } .container-box > .box-front{ background-color:#fffeee; transform: translateZ(200px); } .container-box > .box-after{ background-color:#92ffc8; transform: translateZ(0); } .container-box > .box-left{ background-color:#0316ff; transform: translateX(-100px) translateZ(100px) rotateY(-90deg); } .container-box > .box-right{ background-color:#03dbff; transform: translateX(100px) translateZ(100px) rotateY(90deg); } .container-box > .box-up{ background-color:#ffbe03; transform: translateY(-100px) translateZ(100px) rotateX(90deg); } .container-box > .box-down{ background-color:#ff3e03; transform: translateY(100px) translateZ(100px) rotateX(-90deg); } </style> </head> <body> <div class="container-box"> <div class="box-front">前面</div> <div class="box-after">后面</div> <div class="box-left">左面</div> <div class="box-right">右面</div> <div class="box-up">上面</div> <div class="box-down">下面</div> </div> <script> //閉包、也可以理解為自執(zhí)行函數(shù) (function(){ var animatEle = document.querySelector('div.container-box'); var x = 0, y = 0, z = 0; var animation = function(){ //定義動(dòng)畫(huà) x += +(Math.random().toFixed(2)); y += +(Math.random().toFixed(2)); z += +(Math.random().toFixed(2)); debugger; animatEle.style.transform = `rotateX(${x}deg) rotateY(${y}deg) rotateZ(${z}deg)`; requestAnimationFrame(animation) } requestAnimationFrame(animation);//啟動(dòng)幀動(dòng)畫(huà) }()) </script> </body></html>
關(guān)鍵詞:
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。