您當(dāng)前位置:圖趣網(wǎng)(Tuquu) >> 網(wǎng)頁(yè)設(shè)計(jì)教程 >> 移動(dòng)前端 >> 瀏覽設(shè)計(jì)教程

HTML5+CSS33D展示商品信息示例

強(qiáng)化下perspective和transform:translateZ的用法。傳統(tǒng)的商品展示或許并不能很好的吸引用戶的細(xì)致力,但是假如在展示中添加適當(dāng)?shù)?D元素,~說(shuō)不定結(jié)果不錯(cuò)哈~

結(jié)果圖:

說(shuō)明一下:這個(gè)創(chuàng)意不是我想的,哈~模擬別人的,創(chuàng)意應(yīng)該是w3cplus上的。當(dāng)然了,重點(diǎn)是教大家如何做,就當(dāng)高仿了~

首先,先教大家行使CSS3制作一個(gè)正方體:

在木有CSS前,如許的立方體,應(yīng)該很難制作吧~嗯,我覺(jué)得很難~

html:

<body>  
  
  
<div class="wapper">  
    <div class="cube">  
        <div class="side  front">1</div>  
        <div class="side   back">6</div>  
        <div class="side  right">4</div>  
        <div class="side   left">3</div>  
        <div class="side    top">5</div>  
        <div class="side bottom">2</div>  
    </div>  
</div>  
  
</body>

wapper為此結(jié)果的舞臺(tái),即設(shè)置perspective的元素,假如多個(gè)元素共享一個(gè)舞臺(tái),那么從一個(gè)視線觀察所以的元素的結(jié)果是不一樣的,就相稱(chēng)我們正常情況下,站在一排傾斜成45度的門(mén)前面,每個(gè)門(mén)對(duì)于我們視線來(lái)說(shuō),角度是不同的;div#cube代表一個(gè)立方體,然后6個(gè)DIV分別代表每個(gè)面。

div#cube設(shè)置transform-style:preserve-3d,然后每個(gè)元素設(shè)置rotate和translateZ

如今所有的面重疊在統(tǒng)一個(gè)平面上,我們分別讓?zhuān)?/p>

font往前即Z軸方向移動(dòng)半個(gè)邊長(zhǎng)(translateZ(50px))的距離即50px;

back先繞Y軸旋轉(zhuǎn)180度,如許讓字體是對(duì)外的,然后translateZ(50px),由于此時(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ì)于表現(xiàn)結(jié)果,可以調(diào)節(jié)perspective的距離~

好了,立方體理解了,那么這個(gè)商品展示就沒(méi)什么難度了;兩個(gè)DIV分別代表兩個(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>  
        <div 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>  
        </div>  
    </li>  
  
   <li>  
        <div 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>  
        </div>  
  
    </li>  
  
    <li>  
        <div 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>  
        </div>  
  
    </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),我們給沒(méi)件商品弄了一個(gè)div.wapper看似是多余,其實(shí)不是,由于我們盼望每個(gè)商品都是正常的90deg翻轉(zhuǎn),所以我們不能讓所有的商品共享一個(gè)舞臺(tái),于是我們添加了一個(gè)div.wapper讓他設(shè)置transform-style:preverse-3d,然后每個(gè)li分別設(shè)置舞臺(tái)結(jié)果perspective。最終翻轉(zhuǎn)結(jié)果實(shí)在div.wapper上。

源碼點(diǎn)擊下載

以上就是本文的悉數(shù)內(nèi)容,盼望對(duì)大家的學(xué)習(xí)有所幫助,也盼望大家多多支持圖趣網(wǎng)。

[教程作者:鴻洋_]
免責(zé)聲明:本站文章系圖趣網(wǎng)整理發(fā)布,如需轉(zhuǎn)載,請(qǐng)注明出處,素材資料僅供個(gè)人學(xué)習(xí)與參考,請(qǐng)勿用于商業(yè)用途!
本文地址:http://irelandcustomcontracting.com/tutorial/wd225.html
HTML5+css33D旋轉(zhuǎn)木馬結(jié)果相冊(cè)
詳解前端HTML5幾種存儲(chǔ)體例的總結(jié)
圖趣網(wǎng)微信
建議反饋
×