时间:2023-09-11 17:36:02 | 来源:网站运营
时间:2023-09-11 17:36:02 来源:网站运营
CSS3制作3D页面:CSS3新增了几个有关3D转换属性,本文主要介绍下CSS3的一些属性变换,以及一些酷炫的3D动效如何实现.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> //闭包、也可以理解为自执行函数 (function(){ var animatEle = document.querySelector('div.container-box'); var x = 0, y = 0, z = 0; var animation = function(){ //定义动画 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);//启动帧动画 }()) </script> </body></html>
关键词: