jQuery+CSS3實(shí)現(xiàn)3D立方體旋轉(zhuǎn)效果
本文介紹了如何利用jQuery+CSS3實(shí)現(xiàn)3D立方體旋轉(zhuǎn)效果,先看一看效果圖:

切換圖片過程中,圖片進(jìn)行旋轉(zhuǎn):

HTML結(jié)構(gòu)
3D圖片畫廊的圖片列表和導(dǎo)航按鈕分別使用兩個(gè)無序列表來制作。
<section> <div id="css3dimageslider" class="transparency"> <ul> <li> <img src="img/css3dimg1.jpg"> </li> <li> <img src="img/css3dimg2.jpg"> </li> <li> <img src="img/css3dimg3.jpg"> </li> <li> <img src="img/css3dimg4.jpg"> </li> </ul> </div> <ul id="css3dimagePager"> <li class="active">Image 1</li> <li>Image 2</li> <li>Image 3</li> <li>Image 4</li> </ul> <p id="css3dtransparency" class="active">點(diǎn)擊上面的按鈕切換圖片</p> </section>
CSS樣式
為了制作3D透視效果,需要在#css3dimageslider元素上設(shè)置perspective 透視屬性,并在它里面的無序列表元素上設(shè)置transform-style: preserve-3d;,由于IE瀏覽器不支持這個(gè)屬性,所以在IE瀏覽器中是看不到效果的。接下來通過:nth-child選擇器分別選擇每一個(gè)列表項(xiàng),并通過translateZ和rotateY屬性對(duì)它們進(jìn)行3D轉(zhuǎn)換,形成立方體效果。
#css3dimagePager, #css3dtransparency {
text-align: center;
position: relative;
z-index: 11;
padding: 0 0 10px;
margin: 0;
}
#css3dimagePager li {
padding-right: 2em;
display: inline-block;
cursor: pointer;
}
#css3dimagePager li.active, #css3dtransparency.active {
font-weight: bold;
}
#css3dimageslider {
-webkit-perspective: 800;
-moz-perspective: 800px;
-ms-perspective: 800;
perspective: 800;
-webkit-perspective-origin: 50% 100px;
-moz-perspective-origin: 50% 100px;
-ms-perspective-origin: 50% 100px;
perspective-origin: 50% 100px;
margin: 100px auto 20px auto;
width: 450px;
height: 400px;
}
#css3dimageslider ul {
position: relative;
margin: 0 auto;
height: 281px;
width: 450px;
list-style: none;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transform-origin: 50% 100px 0;
-moz-transform-origin: 50% 100px 0;
-ms-transform-origin: 50% 100px 0;
transform-origin: 50% 100px 0;
-webkit-transition: all 1.0s ease-in-out;
-moz-transition: all 1.0s ease-in-out;
-ms-transition: all 1.0s ease-in-out;
transition: all 1.0s ease-in-out;
}
#css3dimageslider ul li {
position: absolute;
height: 281px;
width: 450px;
padding: 0px;
}
#css3dimageslider ul li:nth-child(1) {
-webkit-transform: translateZ(225px);
-moz-transform: translateZ(225px);
-ms-transform: translateZ(225px);
transform: translateZ(225px);
}
#css3dimageslider ul li:nth-child(2) {
-webkit-transform: rotateY(90deg) translateZ(225px);
-moz-transform: rotateY(90deg) translateZ(225px);
-ms-transform: rotateY(90deg) translateZ(225px);
transform: rotateY(90deg) translateZ(225px);
}
#css3dimageslider ul li:nth-child(3) {
-webkit-transform: rotateY(180deg) translateZ(225px);
-moz-transform: rotateY(180deg) translateZ(225px);
-ms-transform: rotateY(180deg) translateZ(225px);
transform: rotateY(180deg) translateZ(225px);
}
#css3dimageslider ul li:nth-child(4) {
-webkit-transform: rotateY(-90deg) translateZ(225px);
-moz-transform: rotateY(-90deg) translateZ(225px);
-ms-transform: rotateY(-90deg) translateZ(225px);
transform: rotateY(-90deg) translateZ(225px);
}
#css3dimageslider.transparency img {
opacity: 0.7;
}
JavaScript
最后在jQuery代碼中,在點(diǎn)擊按鈕的時(shí)候相應(yīng)的#css3dimageslider ul元素的rotateY屬性,是器旋轉(zhuǎn),并為其添加一個(gè).active class。
<script>
$(document).ready(function() {
$("#css3dimagePager li").click(function(){
var rotateY = ($(this).index() * -90);
$("#css3dimageslider ul").css({"-webkit-transform":"rotateY("+rotateY+"deg)", "-moz-transform":"rotateY("+rotateY+"deg)", "-ms-transform":"rotateY("+rotateY+"deg)", "transform":"rotateY("+rotateY+"deg)"});
$("#css3dimagePager li").removeClass("active");
$(this).addClass("active");
});
$("#css3dtransparency").click(function() {
$("#css3dimageslider").toggleClass("transparency");
$(this).toggleClass("active");
});
});
</script>
以上就是jQuery結(jié)合CSS3來制作3D立方體旋轉(zhuǎn)效果的關(guān)鍵代碼分享,希望對(duì)大家學(xué)習(xí)有所幫助。
- jQuery實(shí)現(xiàn)圖像旋轉(zhuǎn)動(dòng)畫效果
- 基于jQuery插件實(shí)現(xiàn)環(huán)形圖標(biāo)菜單旋轉(zhuǎn)切換特效
- jQuery右下角旋轉(zhuǎn)環(huán)狀菜單特效代碼
- jQuery制作圖片旋轉(zhuǎn)效果
- jQuery實(shí)現(xiàn)炫麗的3d旋轉(zhuǎn)星空效果
- jquery實(shí)現(xiàn)LED廣告牌旋轉(zhuǎn)系統(tǒng)圖片切換效果代碼分享
- jQuery實(shí)現(xiàn)的模仿雨滴下落動(dòng)畫效果
- jQuery實(shí)現(xiàn)數(shù)字自動(dòng)增加或者減少的動(dòng)畫效果示例
- jQuery實(shí)現(xiàn)切換頁面過渡動(dòng)畫效果
- jQuery實(shí)現(xiàn)點(diǎn)擊旋轉(zhuǎn),再點(diǎn)擊恢復(fù)初始狀態(tài)動(dòng)畫效果示例
相關(guān)文章
jquery實(shí)現(xiàn)鼠標(biāo)滑過顯示二級(jí)下拉菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)鼠標(biāo)滑過顯示二級(jí)下拉菜單效果,通過jquery操作鼠標(biāo)事件及頁面樣式動(dòng)態(tài)變換實(shí)現(xiàn)該功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08
jquery實(shí)現(xiàn)美觀的導(dǎo)航菜單鼠標(biāo)提示特效代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)美觀的導(dǎo)航菜單鼠標(biāo)提示特效代碼,涉及jquery鼠標(biāo)事件及頁面animate動(dòng)畫的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-09-09
jQuery實(shí)現(xiàn)的省市縣三級(jí)聯(lián)動(dòng)菜單效果完整實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的省市縣三級(jí)聯(lián)動(dòng)菜單效果,結(jié)合完整實(shí)例形式分析了jQuery數(shù)組操作及事件響應(yīng)的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2016-08-08
jQuery實(shí)現(xiàn)淡入淡出二級(jí)下拉導(dǎo)航菜單的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)淡入淡出二級(jí)下拉導(dǎo)航菜單的方法,涉及jquery簡單操作頁面元素展開與隱藏的實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08
自己動(dòng)手制作jquery插件之自動(dòng)添加刪除行功能介紹
這個(gè)插件的上篇訪問量很不好,幾乎是我寫的文章里最少的點(diǎn)擊量的了,不知道是不是因?yàn)榇蠹覍?duì)我說的這個(gè)插件不感興趣還是說我寫的東西技術(shù)含量太差了,呵,那我只能孤芳自賞了2011-10-10

