溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

css怎么實(shí)現(xiàn)3D圖像輪轉(zhuǎn)效果

發(fā)布時間:2023-01-04 09:27:28 來源:億速云 閱讀:90 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要講解了“css怎么實(shí)現(xiàn)3D圖像輪轉(zhuǎn)效果”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“css怎么實(shí)現(xiàn)3D圖像輪轉(zhuǎn)效果”吧!

首先看html文件,div.billboard為效果的容器,利用10個div.poster分割圖像,每個poster中有三個face,分別用來承載三個圖像。

XML/HTML Code復(fù)制內(nèi)容到剪貼板

<div class="billboard">     
    <div class="poster">     
        <div class="face panel1 p1"></div>     
        <div class="face panel2 p1"></div>     
        <div class="face panel3 p1"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p2"></div>     
        <div class="face panel2 p2"></div>     
        <div class="face panel3 p2"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p3"></div>     
        <div class="face panel2 p3"></div>     
        <div class="face panel3 p3"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p4"></div>     
        <div class="face panel2 p4"></div>     
        <div class="face panel3 p4"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p5"></div>     
        <div class="face panel2 p5"></div>     
        <div class="face panel3 p5"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p6"></div>     
        <div class="face panel2 p6"></div>     
        <div class="face panel3 p6"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p7"></div>     
        <div class="face panel2 p7"></div>     
        <div class="face panel3 p7"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p8"></div>     
        <div class="face panel2 p8"></div>     
        <div class="face panel3 p8"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p9"></div>     
        <div class="face panel2 p9"></div>     
        <div class="face panel3 p9"></div>     
    </div>     
    <div class="poster">     
        <div class="face panel1 p10"></div>     
        <div class="face panel2 p10"></div>     
        <div class="face panel3 p10"></div>     
    </div>     
</div>

CSS文件這里我們用到了sass,用的是scss語法。

CSS Code復(fù)制內(nèi)容到剪貼板

//變量初始化     
//圖像分塊個數(shù),如要更改,html需要進(jìn)行相應(yīng)的修改     
$numPoster:10;      
     
//輪換圖像個數(shù),如要更改,html需要進(jìn)行相應(yīng)的修改     
$numFace:3;      
     
//圖像寬度      
$width:600px;      
     
//圖像高度      
$height:320px;      
     
//盒子的設(shè)置     
.billboard {       
    width:$width;       
    margin:100px auto;       
}      
     
//圖像條左浮動      
.poster {       
    float:left;       
    width:$width/$numPoster;       
    height:$height;       
}     
     
//圖像條面的統(tǒng)一設(shè)置,絕對定位、3d動畫設(shè)置       
.face {       
    position:absolute;       
    height:$height;       
    width:$width/$numPoster;       
    transform-origin:50% 50% -17px;       
    backface-visibility: hidden;       
    transform-style:preserve-3d;       
    perspective:350px;       
}       
     
//圖像條面分別設(shè)置背景圖像、動畫     
@for $i from 1 through $numFace{       
  .poster .panel#{$i} {       
    background:url(http://gx.zptc.cn/whqet/img/#{$i}.jpg);       
    transform:transformY(360deg/$numFace*($i - 1));       
    animation: rotateMe#{$i} 10s infinite;       
  }       
  @keyframes rotateMe#{$i} {       
    0% {       
        transform:rotateY(360deg/$numFace*($i - 1));       
    }       
    9% {       
        transform:rotateY(360deg/$numFace*($i - 1));       
    }       
    24% {       
        transform:rotateY(360deg/$numFace*($i));       
    }       
    42% {       
        transform:rotateY(360deg/$numFace*($i));       
    }       
    57% {       
        transform:rotateY(360deg/$numFace*($i + 1));       
    }       
    75% {       
        transform:rotateY(360deg/$numFace*($i + 1));       
    }       
    90% {       
        transform:rotateY(360deg/$numFace*($i + 2));       
    }       
    100% {       
        transform:rotateY(360deg/$numFace*($i + 2));       
    }       
  }       
}      
     
//圖像條面的背景偏移     
@for $i from 1 through $numPoster {       
  .poster .p#{$i} {background-position:-($width/$numPoster*($i - 1)) top;}       
}

css的基本語法是什么

css的基本語法是:

1、css規(guī)則由選擇器和一條或多條聲明兩個部分構(gòu)成;

2、選擇器通常是需要改變樣式的HTML元素;

3、每條聲明由一個屬性和一個值組成;

4、屬性和屬性值被冒號分隔開。

感謝各位的閱讀,以上就是“css怎么實(shí)現(xiàn)3D圖像輪轉(zhuǎn)效果”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對css怎么實(shí)現(xiàn)3D圖像輪轉(zhuǎn)效果這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI