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

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

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

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

效果圖如下:

不再采用ul li的布局方式

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

實例源碼

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</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)方式

效果圖如下:

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

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

實例源碼

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</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>標題</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>

總結

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

相關文章

最新評論

通渭县| 陇川县| 都匀市| 乐安县| 岐山县| 白沙| 景宁| 江达县| 青海省| 连江县| 大石桥市| 托克托县| 大方县| 紫金县| 台州市| 乌兰县| 龙陵县| 雅安市| 南涧| 三明市| 文化| 柘城县| 融水| 颍上县| 虞城县| 车险| 陇川县| 航空| 新宁县| 广汉市| 英超| 高密市| 海安县| 黑河市| 射阳县| 长沙市| 连城县| 永修县| 磴口县| 河东区| 合江县|