好的各位小伙伴
今天咱們來做一個
3D的旋轉(zhuǎn)盒子
制作3D旋轉(zhuǎn)盒子
老規(guī)矩筷屡,不要急著動手先來分析一波腿箩。先不管旋轉(zhuǎn),3D盒子首先就是一個盒子金蜀,由六個面組成刷后。就像下面這樣:
我們要做的就是,先在平面上繪制六個面渊抄,然后給圖片一個3D的環(huán)境尝胆,把六個面組成一個正方體的盒子。那么分析就到這里了护桦,下面我們開始實踐吧~
這樣就把這六個面制作出來了含衔,為了區(qū)分還加了編號。先在我們看著這六個面是重疊在一起的二庵。
現(xiàn)在我們來給盒子的六個面進行定位贪染。
其他的幾個面都移動了位置,現(xiàn)在只有1號面和6號面重疊在一起了催享。
現(xiàn)在來給盒子設置景深杭隙,方便我們來制作3D的盒子。
給盒子一個旋轉(zhuǎn)的效果因妙,現(xiàn)在立體感是不是明顯了很多~
現(xiàn)在我們來給這個正方體的六個面進行空間定位痰憎。
僅僅是定位是不夠的,還需要給面進行旋轉(zhuǎn)攀涵,這些之前的文章有介紹就不贅述了
大盒子的3d效果完成了铣耘,下面制作小盒子的工作就簡單了,直接把制作大盒子的代碼復制一下汁果,修改一下代碼就可以顯示兩個盒子了涡拘。
現(xiàn)在大盒子套小盒子的效果完成了,還可以是吧~
最后一步据德,給小盒子添加背景圖片鳄乏,并且修改盒子的動作(大盒子開蓋,小盒子從大盒子中出來)棘利。
最終效果:
我們的3D盒子旋轉(zhuǎn)效果就做出來了橱野,這只是一個雛形,大家可以開動腦經(jīng)善玫,來豐富這個效果水援,快來動手給身邊的伙伴顯擺一下吧~
(注意選好對象,被打臉了本人概不負責)
Title
*{margin:0;padding:0;}
body,ul,li,ol,dl,dd,p,h1,h2,h3,h4,h5,h6{?margin:0;}
a{text-decoration:none;color: inherit;}
img{display: block;border:none;}
ol,ul{list-style:none;}
.clearfix:after?{content:?"";display: block;clear: both;}
.fl{?float: left;}
.fr{?float: right;}
.main{?position: relative;?width:?400px;?height:?400px;?margin:?200px?auto;
box-shadow:?0?0?10px?0?#000;?border:?1px?solid transparent;?perspective:?800px;}
/*大盒子*/
.main?.bigBox?{?position: relative;?width:?200px;?height:?200px;
margin:?100px?auto;?transform-style: preserve-3d;animation: move?4s?infinite alternate;}
.main?.bigBox?p{?position: absolute;?width:?200px;?height:?200px;
box-shadow:?0?0?10px?0?red;font: bold?30px/200px?"";?color: red;?text-align: center; }
/*小盒子*/
.main?.smallBox?{?position: absolute;?left:?calc(50% - 50px);?top:?calc(50% - 50px);
width:?100px;?height:?100px;transform-style: preserve-3d;animation: play2?4s?infinite alternate;}
.main?.smallBox?p{?position: absolute;width:?100px;?height:?100px;
box-shadow:?0?0?10px?0?red;font: bold?30px/100px?"";?color: red;?text-align: center; }
/*大盒子布局*/
.main?.bigBox?p:nth-child(1){?left:?0;?top:?0;?transform:?translateZ(100px); }
.main?.bigBox?p:nth-child(2){?left: -200px;?top:?0;?transform:?translateZ(100px)?rotateY(-90deg);
transform-origin: right; }
.main?.bigBox?p:nth-child(3){?left:?200px;?top:?0;?transform:?translateZ(100px)?rotateY(90deg);
transform-origin: left; }
.main?.bigBox?p:nth-child(4){?left:?0;?top: -200px;?transform:?translateZ(100px)?rotateX(90deg);
transform-origin: bottom;?animation: play1?4s?infinite alternate;}
.main?.bigBox?p:nth-child(5){?left:?0;?top:?200px;?transform:?translateZ(100px)?rotateX(-90deg);
transform-origin: top; }
.main?.bigBox?p:nth-child(6){?left:?0;?top:?0;?transform:?translateZ(-100px); }
/*小盒子布局*/
.main?.smallBox?p:nth-child(1){?left:?0;?top:?0;?background:?url("img/1.jpg")no-repeat?center/cover;transform:?translateZ(50px); }
.main?.smallBox?p:nth-child(2){?left: -100px;?top:?0;background:?url("img/2.jpg")no-repeat?center/cover;?transform:?translateZ(50px)?rotateY(-90deg);
transform-origin: right; }
.main?.smallBox?p:nth-child(3){?left:?100px;?top:?0;background:?url("img/3.jpg")no-repeat?center/cover;?transform:?translateZ(50px)?rotateY(90deg);
transform-origin: left; }
.main?.smallBox?p:nth-child(4){?left:?0;?top: -100px;background:?url("img/4.jpg")no-repeat?center/cover;?transform:?translateZ(50px)?rotateX(90deg);
transform-origin: bottom; }
.main?.smallBox?p:nth-child(5){?left:?0;?top:?100px;background:?url("img/5.jpg")no-repeat?center/cover;?transform:?translateZ(50px)?rotateX(-90deg);
transform-origin: top; }
.main?.smallBox?p:nth-child(6){?left:?0;?top:?0;background:?url("img/6.jpg")no-repeat?center/cover;?transform:?translateZ(-50px); }
@-webkit-keyframes?move {
to{?transform:?rotateY(90deg);}
}
@-webkit-keyframes?play1 {
to{?transform:?translateZ(100px)?rotateX(0deg);}
}
@-webkit-keyframes?play2 {
to{?transform:?rotateY(90deg);?top: -50px;}
}
今天就到這里了
小伙伴們再見了