最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用Js+Css實現(xiàn)折紙動態(tài)導(dǎo)航效果實例源碼

 更新時間:2017年01月25日 09:55:33   投稿:daisy  
這篇文章主要給大家介紹了利用Js+Css實現(xiàn)折紙動態(tài)導(dǎo)航的效果,實現(xiàn)后的效果非常不錯,文中給出了簡單的介紹和完整的實例代碼,對大家具有一定的參考價值,有需要的朋友們下面來一起看看吧。

先來看看第一種實現(xiàn)方式

效果圖如下:

不再采用ul li的布局方式

-webkit-transform-style:preserve-3d只對子元素有作用,所以每個div都加。

實例源碼

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標(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>第一項</span>
 <div>
  <span>第二項</span>
  <div>
   <span>第三項</span>
   <div>
    <span>第四項</span>
    <div>
    <span>第五項</span>
     <div>
      <span>第六項</span>
      <div>
       <span>第七項</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>

第二種實現(xiàn)方式

效果圖如下:

這個原先是隱藏的,點擊后才展開。

通過關(guān)鍵幀控制每個div的展開狀態(tài),當(dāng)要展開的時候給每個div添加className,但是這個className不是一下子全部添加上去的,而是有延時的,所以用到了定時器。

實例源碼

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標(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>第一項</span>
  <div>
   <span>第二項</span>
   <div>
    <span>第三項</span>
    <div>
     <span>第四項</span>
     <div>
      <span>第五項</span>
      <div>
       <span>第六項</span>
       <div>
        <span>第七項</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é)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。

相關(guān)文章

最新評論

抚宁县| 景德镇市| 柏乡县| 宜兴市| 固镇县| 华蓥市| 来凤县| 清远市| 彭阳县| 安泽县| 新巴尔虎左旗| 辽阳市| 安宁市| 北流市| 永福县| 彭水| 湘潭市| 天水市| 巨野县| 饶河县| 淅川县| 崇礼县| 石景山区| 宁明县| 巴南区| 文水县| 沿河| 河东区| 五寨县| 诏安县| 万山特区| 泸水县| 太仓市| 安泽县| 木里| 社会| 河东区| 灌南县| 仙游县| 同仁县| 志丹县|