利用Js+Css實(shí)現(xiàn)折紙動(dòng)態(tài)導(dǎo)航效果實(shí)例源碼
先來(lái)看看第一種實(shí)現(xiàn)方式
效果圖如下:


不再采用ul li的布局方式
-webkit-transform-style:preserve-3d只對(duì)子元素有作用,所以每個(gè)div都加。
實(shí)例源碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無(wú)標(biāo)題文檔</title>
<style>
.wrap{margin:30px auto;width:302px;-webkit-perspective:800px; -webkit-transform-style:preserve-3d; position:relative;}
.wrap div{ position:absolute; top:52px;left:0;-webkit-transform-style:preserve-3d; -webkit-transform-origin:top;}
.wrap span{ display:block;width:300px;border:1px solid #000;height:50px; font:16px/50px "宋體"; background:#ccc;}
</style>
</head>
<body>
<input type="button" value="展開" />
<input type="button" value="收縮" />
<div class="wrap" id="list">
<span>第一項(xiàng)</span>
<div>
<span>第二項(xiàng)</span>
<div>
<span>第三項(xiàng)</span>
<div>
<span>第四項(xiàng)</span>
<div>
<span>第五項(xiàng)</span>
<div>
<span>第六項(xiàng)</span>
<div>
<span>第七項(xiàng)</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
window.onload=function()
{
var oList=document.getElementById("list");
var aDiv=oList.getElementsByTagName("div");
var aBtn=document.getElementsByTagName("input");
aBtn[1].onclick=function()
{
for(var i=0;i<aDiv.length;i++)
{
aDiv[i].style.transition="0.5s "+(aDiv.length-i)*100+"ms";
aDiv[i].style.WebkitTransform="rotateX(60deg)";
}
};
aBtn[0].onclick=function()
{
for(var i=0;i<aDiv.length;i++)
{
aDiv[i].style.transition="0.5s "+i*100+"ms";
aDiv[i].style.WebkitTransform="rotateX(0deg)";
}
};
};
</script>
</body>
</html>
第二種實(shí)現(xiàn)方式
效果圖如下:


這個(gè)原先是隱藏的,點(diǎn)擊后才展開。
通過(guò)關(guān)鍵幀控制每個(gè)div的展開狀態(tài),當(dāng)要展開的時(shí)候給每個(gè)div添加className,但是這個(gè)className不是一下子全部添加上去的,而是有延時(shí)的,所以用到了定時(shí)器。
實(shí)例源碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無(wú)標(biāo)題文檔</title>
<style>
@-webkit-keyframes open{
0%
{
-webkit-transform:rotateX(-120deg);
}
40%
{
-webkit-transform:rotateX(30deg);
}
60%
{
-webkit-transform:rotateX(-20deg);
}
80%
{
-webkit-transform:rotateX(10deg);
}
100%
{
-webkit-transform:rotateX(0deg);
}
}
.wrap{margin:30px auto;width:300px;-webkit-perspective:800px;position:relative;}
.wrap h2{ height:50px;background:#F03; text-align:center; font:16px/50px "微軟雅黑"; color:#fff; position:relative;z-index:2;}
.wrap div{ position:absolute; top:32px;left:0;-webkit-transform-style:preserve-3d; -webkit-transform-origin:top; -webkit-transform:rotateX(-120deg); transition:.5s;}
.wrap>div{ top:50px;}
.wrap .open{-webkit-animation:open 2s;-webkit-transform:rotateX(0deg);}
.wrap span{ display:block;width:300px;height:30px; font:14px/30px "宋體"; background:#6F3; text-indent:15px; color:#fff; transition:.5s; box-shadow:inset 0 0 30px 20px rgba(0,0,0,1);}
.wrap .open>span{box-shadow:inset 0 0 30px 10px rgba(0,0,0,0);}
.wrap span:hover{ background:#FF0;text-indent:30px;}
</style>
</head>
<body>
<input type="button" value="展開" />
<input type="button" value="收縮" />
<div class="wrap" id="list">
<h2>標(biāo)題</h2>
<div>
<span>第一項(xiàng)</span>
<div>
<span>第二項(xiàng)</span>
<div>
<span>第三項(xiàng)</span>
<div>
<span>第四項(xiàng)</span>
<div>
<span>第五項(xiàng)</span>
<div>
<span>第六項(xiàng)</span>
<div>
<span>第七項(xiàng)</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
window.onload=function()
{
var oList=document.getElementById("list");
var aDiv=oList.getElementsByTagName("div");
var aBtn=document.getElementsByTagName("input");
var oTimer=null;
aBtn[1].onclick=function()
{
var i=aDiv.length-1;
clearInterval(oTimer);
oTimer=setInterval(function(){
aDiv[i].className="";
i--;
if(i<0)
{
clearInterval(oTimer);
}
},50);
};
aBtn[0].onclick=function()
{
var i=0;
clearInterval(oTimer);
oTimer=setInterval(function(){
aDiv[i].className="open";
i++;
if(i==aDiv.length)
{
clearInterval(oTimer);
}
},200);
};
};
</script>
</body>
</html>
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流。
- JS+CSS實(shí)現(xiàn)鼠標(biāo)滑過(guò)時(shí)動(dòng)態(tài)翻滾的導(dǎo)航條效果
- javascript實(shí)現(xiàn)的鼠標(biāo)懸停時(shí)動(dòng)態(tài)翻滾的導(dǎo)航條
- JS實(shí)現(xiàn)移動(dòng)端可折疊導(dǎo)航菜單(現(xiàn)代都市風(fēng))
- JS無(wú)限級(jí)導(dǎo)航菜單實(shí)現(xiàn)方法
- vuejs 切換導(dǎo)航條高亮(路由菜單高亮)的方法示例
- js實(shí)現(xiàn)水平滾動(dòng)菜單導(dǎo)航
- 原生JS實(shí)現(xiàn)導(dǎo)航下拉菜單效果
- 如何使用wheelnav.js構(gòu)建酷炫的動(dòng)態(tài)導(dǎo)航菜單
相關(guān)文章
javascript操作元素的常見(jiàn)方法小結(jié)
這篇文章主要介紹了javascript操作元素的常見(jiàn)方法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript針對(duì)頁(yè)面元素動(dòng)態(tài)獲取、賦值、動(dòng)態(tài)操作相關(guān)使用技巧,需要的朋友可以參考下2019-11-11
關(guān)于JavaScript的單雙引號(hào)嵌套問(wèn)題
單引號(hào)和雙引號(hào)之間可以相互嵌套。接下來(lái)通過(guò)本文給大家介紹JavaScript的單雙引號(hào)嵌套問(wèn)題 ,感興趣的朋友一起看看吧2017-08-08
詳解bootstrap的modal-remote兩種加載方式【強(qiáng)化】
本篇文章主要介紹了詳解bootstrap的modal-remote兩種加載方式【強(qiáng)化】,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01
js實(shí)現(xiàn)九宮格圖片半透明漸顯特效的方法
這篇文章主要介紹了js實(shí)現(xiàn)九宮格圖片半透明漸顯特效的方法,涉及js操作css特效的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-02-02
JavaScript中動(dòng)態(tài)向表格添加數(shù)據(jù)
本文給大家分享使用原生javascript實(shí)現(xiàn)動(dòng)態(tài)向表格中添加數(shù)據(jù)的方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-01-01
使用純javascript實(shí)現(xiàn)經(jīng)典掃雷游戲
本文給大家分享的是個(gè)人剛開始學(xué)習(xí)javascript的時(shí)候?qū)懙姆聎indows經(jīng)典的掃雷游戲的代碼,當(dāng)時(shí)只是寫了下來(lái),沒(méi)加注釋,這里補(bǔ)上,有需要的小伙伴可以參考下。2015-04-04
js中對(duì)函數(shù)設(shè)置默認(rèn)參數(shù)值的3種方法
這篇文章主要介紹了js中對(duì)函數(shù)設(shè)置默認(rèn)參數(shù)值的3種方法嗎,3種方法都具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-10-10

