亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

純CSS3實現(xiàn)3D旋轉(zhuǎn)書本效果

  發(fā)布時間:2016-03-21 15:04:15   作者:陳小峰   我要評論
有一些前沿的電商網(wǎng)站已經(jīng)開始使用3D模型來展示商品并支持在線定制,而其中圖書的展示是最為簡單的一種,無需復(fù)雜的建模過程,使用圖片和CSS3的一些變換即可實現(xiàn)更好的展示效果,簡潔而實用,接下來通過本文給大家介紹CSS3實現(xiàn)3D旋轉(zhuǎn)書本效果,需要的朋友一起學(xué)習(xí)

有一些前沿的電商網(wǎng)站已經(jīng)開始使用3D模型來展示商品并支持在線定制,而其中圖書的展示是最為簡單的一種,無需復(fù)雜的建模過程,使用圖片和CSS3的一些變換即可實現(xiàn)更好的展示效果,簡潔而實用。
書本的3D模型是所有商品中最為簡單的,因為其本質(zhì)上就是一個立方體(cube),只是帶有封面/封底和左側(cè)封條。 所以要構(gòu)造一個3D書本展示,問題就被分解為構(gòu)造一個立方體+旋轉(zhuǎn)+圖片背景。
1. 構(gòu)造一個立方體
要創(chuàng)建一個立方體,首先我們需要創(chuàng)建一個虛擬的三維視覺空間,這可以通過設(shè)置包容器元素的perspective屬性獲得。


CSS Code復(fù)制內(nèi)容到剪貼板
  1. .stage {    
  2. width200px;    
  3. height260px;    
  4. perspective: 1000px;    
  5. perspective-origin: center center;// 缺省值,可忽略    
  6. }  
上述代碼把元素放在距離觀察點1000px的地方(Z軸向),并且在X/Y軸向上居中。
CSS Code復(fù)制內(nèi)容到剪貼板
  1. <div class="stage">    
  2. <div class="cube">    
  3. <figure class="back"></figure>    
  4. <figure class="top"></figure>    
  5. <figure class="bottom"></figure>    
  6. <figure class="left"></figure>    
  7. <figure class="right"></figure>    
  8. <figure class="front"></figure>    
  9. </div>    
  10. </div>   
接著,我們在包容器元素里面添加一個立方體元素,6個邊(上下左右和前后),之所以使用figure,是因為需要支持貼圖。
我們需要根據(jù)書本的厚度和長寬來確定立方體各個面的坐標(biāo)位置,在本例中所用書本模型(一本MySQL書)的絕對厚度為18.2px,高度260px,寬度197.6px。
那么根據(jù)簡單的幾何知識,前后面距離立方體中心的距離為18.2/2=9.1px,其中“后”元素需要再翻轉(zhuǎn)一下(即“背”過去)。
CSS Code復(fù)制內(nèi)容到剪貼板
  1. .front {    
  2. transform: translateZ(9.1px);    
  3. }    
  4. .back {    
  5. transform: rotateY(180deg) translateZ(9.1px);    
  6. }   
用類似的計算方法,我們可以把其他4條邊放置(平移+旋轉(zhuǎn)變換)到各自的位置,從而拼裝成一個虛擬的立方體。
CSS Code復(fù)制內(nèi)容到剪貼板
  1. .front {    
  2. transform: translateZ(9.1px);    
  3. }    
  4. .back {    
  5. transform: rotateY(180deg) translateZ(9.1px);    
  6. }    
  7. .top {    
  8. transform: rotateX(90deg) rotateZ(90deg) translateZ(98.8px) translateY(-89.7px);    
  9. width: 18.2px;    
  10. height: 197.6px;    
  11. }    
  12. .bottombottom {    
  13. transform: rotateX(-90deg) rotateZ(90deg) translateZ(161.2px) translateY(-89.7px);    
  14. }    
  15. .left {    
  16. transform: rotateY(-90deg) translateZ(9.1px);    
  17. width: 18.2px;    
  18. }    
  19. .rightright {    
  20. transform: rotateY(90deg) translateZ(188.5px);    
  21. width: 18.2px;    
  22. }  
2. 添加封面
接著我們給前后以及左側(cè)面元素添加背景圖(可以使用一張圖,然后從不同的位置截?。o其他3個面添加背景顏色,并給“底”面添加陰影效果:
CSS Code復(fù)制內(nèi)容到剪貼板
  1. .front {    
  2. transform: translateZ(9.1px);    
  3. backgroundurl("//wow.techbrood.com/uploads/160301/mysql.png"top rightright;    
  4. background-sizeauto 100%;    
  5. }    
  6. .back {    
  7. transform: rotateY(180deg) translateZ(9.1px);    
  8. backgroundurl("//wow.techbrood.com/uploads/160301/mysql.png"top left;    
  9. background-sizeauto 100%;    
  10. }    
  11. .top {    
  12. transform: rotateX(90deg) rotateZ(90deg) translateZ(98.8px) translateY(-89.7px);    
  13. background#fafafa;    
  14. width: 18.2px;    
  15. height: 197.6px;    
  16. }    
  17. .bottombottom {    
  18. transform: rotateX(-90deg) rotateZ(90deg) translateZ(161.2px) translateY(-89.7px);    
  19. background#ccc;    
  20. width: 18.2px;    
  21. height: 197.6px;    
  22. -webkit-filter: drop-shadow(0 0 26px rgba(0, 0, 0, 0.75));    
  23. }    
  24. .left {    
  25. transform: rotateY(-90deg) translateZ(9.1px);    
  26. backgroundurl("//wow.techbrood.com/uploads/160301/mysql.png"top center;    
  27. background-sizeauto 100%;    
  28. width: 18.2px;    
  29. }    
  30. .rightright {    
  31. transform: rotateY(90deg) translateZ(188.5px);    
  32. background#ddd;    
  33. background-sizeauto 100%;    
  34. width: 18.2px;    
  35. }  
這樣我們就實現(xiàn)了一個逼真的3D書本視覺模型。
3. 添加旋轉(zhuǎn)動畫
這個比較簡單,使用rotateY方法就可以。
CSS Code復(fù)制內(nèi)容到剪貼板
  1. @-webkit-keyframes rotate {    
  2. 0% {    
  3. transform: rotateY(0) translateX(-18.2px);    
  4. }    
  5. 100% {    
  6. transform: rotateY(360deg) translateX(-18.2px);    
  7. }    
  8. }  

最終的效果圖如下:

關(guān)于CSS3實現(xiàn)3D旋轉(zhuǎn)書本 的全部內(nèi)容小編就給大家介紹這么多,希望對大家有所幫助!
原文:http://blog.csdn.net/iefreer/article/details/50931478

相關(guān)文章

最新評論