小編給大家分享一下HTML5和CSS3怎么弄3D展示商品信息,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營(yíng)銷推廣、網(wǎng)站重做改版、穆棱網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為穆棱等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
強(qiáng)化下perspective和transform:translateZ的用法。傳統(tǒng)的商品展示或許并不能很好的吸引用戶的注意力,但是如果在展示中添加適當(dāng)?shù)?D元素,~說(shuō)不定效果不錯(cuò)哈~
效果圖:
說(shuō)明一下:這個(gè)創(chuàng)意不是我想的,哈~模仿別人的,創(chuàng)意應(yīng)該是w3cplus上的。當(dāng)然了,重點(diǎn)是教大家如何做,就當(dāng)高仿了~
首先,先教大家利用CSS3制作一個(gè)正方體:
在木有CSS前,這樣的立方體,應(yīng)該很難制作吧~嗯,我覺得很難~
html:
<body> <p class="wapper"> <p class="cube"> <p class="side front">1</p> <p class="side back">6</p> <p class="side right">4</p> <p class="side left">3</p> <p class="side top">5</p> <p class="side bottom">2</p> </p> </p> </body>
wapper為此效果的舞臺(tái),即設(shè)置perspective的元素,如果多個(gè)元素共享一個(gè)舞臺(tái),那么從一個(gè)視線觀察所以的元素的效果是不一樣的,就相當(dāng)我們正常情況下,站在一排傾斜成45度的門前面,每個(gè)門對(duì)于我們視線來(lái)說(shuō),角度是不同的;p#cube代表一個(gè)立方體,然后6個(gè)p分別代表每個(gè)面。
p#cube設(shè)置transform-style:preserve-3d,然后每個(gè)元素設(shè)置rotate和translateZ
現(xiàn)在所有的面重疊在同一個(gè)平面上,我們分別讓:
font往前即Z軸方向移動(dòng)半個(gè)邊長(zhǎng)(translateZ(50px))的距離即50px;
back先繞Y軸旋轉(zhuǎn)180度,這樣讓字體是對(duì)外的,然后translateZ(50px),因?yàn)榇藭r(shí)已經(jīng)旋轉(zhuǎn)了180度,所以tanslateZ是向下的,
同理,其他面分別繞X軸或者Y軸旋轉(zhuǎn)90度,然后translateZ(50px)
CSS:
.wapper { margin: 100px auto 0; width: 100px; height: 100px; -webkit-perspective: 1200px; font-size: 50px; font-weight: bold; color: #fff; } .cube { position: relative; width: 100px; -webkit-transform: rotateX(-40deg) rotateY(32deg); -webkit-transform-style: preserve-3d; } .side { text-align: center; line-height: 100px; width: 100px; height: 100px; background: rgba(255, 99, 71, 0.6); border: 1px solid rgba(0, 0, 0, 0.5); position: absolute; } .front { -webkit-transform: translateZ(50px); } .top { -webkit-transform: rotateX(90deg) translateZ(50px); } .right { -webkit-transform: rotateY(90deg) translateZ(50px); } .left { -webkit-transform: rotateY(-90deg) translateZ(50px); } .bottom { -webkit-transform: rotateX(-90deg) translateZ(50px); } .back { -webkit-transform: rotateY(-180deg) translateZ(50px); }
對(duì)于顯示效果,可以調(diào)節(jié)perspective的距離~
好了,立方體理解了,那么這個(gè)商品展示就沒什么難度了;兩個(gè)p分別代表兩個(gè)面,一個(gè)是圖片,一個(gè)是介紹,初始時(shí),介紹繞X軸先旋轉(zhuǎn)90deg,然后當(dāng)鼠標(biāo)移動(dòng)時(shí),將整個(gè)盒子繞x軸旋轉(zhuǎn)90deg即可。
HTML:
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> <link href="css/reset.css" rel="stylesheet" type="text/css"> </head> <body> <ul id="content"> <li> <p class="wrapper"> <img src="images/a.png"> <span class="information"> <strong>Contact Form</strong> The easiest way to add a contact form to your shop. </span> </p> </li> <li> <p class="wrapper"> <img src="images/b.jpeg"> <span class="information"> <strong>Contact Form</strong> The easiest way to add a contact form to your shop. </span> </p> </li> <li> <p class="wrapper"> <img src="images/c.png"> <span class="information"> <strong>Contact Form</strong> The easiest way to add a contact form to your shop. </span> </p> </li> </ul> </body> </html>
CSS:
<style type="text/css"> body { font-family: Tahoma, Arial; } #content { margin: 100px auto 0; } #content li, #content .wrapper, #content li img, #content li span { width: 310px; height: 100px; } #content li { cursor: pointer; -webkit-perspective: 4000px; width: 310px; height: 100px; float: left; margin-left: 60px; /*box-shadow: 2px 2px 5px #888888;*/ } #content .wrapper { position: relative; -webkit-transform-style: preserve-3d; -webkit-transition: -webkit-transform .6s; } #content li img { top: 0; border-radius: 3px; box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.3); position: absolute; -webkit-transform: translateZ(50px); -webkit-transition: all .6s; } #content li span { background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(236, 241, 244, 1)), color-stop(100%, rgba(190, 202, 217, 1))); text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.5); position: absolute; -webkit-transform: rotateX(-90deg) translateZ(50px); -webkit-transition: all .6s; display: block; top: 0; text-align: left; border-radius: 15px; font-size: 12px; padding: 10px; width: 290px; height: 80px; text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.5); box-shadow: none; } #content li span strong { display: block; margin: .2em 0 .5em 0; font-size: 20px; font-family: "Oleo Script"; } #content li:hover .wrapper { -webkit-transform: rotateX(95deg); } #content li:hover img { box-shadow: none; border-radius: 15px; } #content li:hover span { box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.3); border-radius: 3px; } </style>
CSS基本在上面已經(jīng)分析過(guò)了,這里說(shuō)明一點(diǎn),我們給沒件商品弄了一個(gè)p.wapper看似是多余,其實(shí)不是,因?yàn)槲覀兿M總€(gè)商品都是正常的90deg翻轉(zhuǎn),所以我們不能讓所有的商品共享一個(gè)舞臺(tái),于是我們添加了一個(gè)p.wapper讓他設(shè)置transform-style:preverse-3d,然后每個(gè)li分別設(shè)置舞臺(tái)效果perspective。最終翻轉(zhuǎn)效果實(shí)在p.wapper上。
以上是HTML5和CSS3怎么弄3D展示商品信息的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
新聞名稱:HTML5和CSS3怎么弄3D展示商品信息
標(biāo)題URL:http://chinadenli.net/article26/gppjcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、企業(yè)建站、ChatGPT、建站公司、標(biāo)簽優(yōu)化、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)