一個不錯的JS動態左側菜單[收藏]

來源:互聯網
上載者:User

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
body{margin:10px;padding:10px;}
body,h2,div,span,li{font-size:12px;}
.title01,.title02 {color:#fff;font-weight:bold;}
#DoorP{border:12px solid #eee;width:150px;padding:4px;background:#fff;}
h2{text-align:center;margin:0px;padding:0px;line-height:22px;}
.title01{width:100%;height:25px;background:#00ccff;cursor:pointer;}
.title02{width:100%;height:25px;background:#99cc00;cursor:pointer;}
.content{background:#eee;border-bottom:2px solid #fff;overflow:hidden;color:#666;padding-left:4px;padding-right:4px;line-height:18px;}
.content a:link,.content a:visited{color:#666666;text-decoration:none;}
.content a:hover{color:#FF6600;text-decoration:underline;}
</style>
<title></title>
</head>

<body>
<div id="DoorP">
  <h2>第一層資訊</h2>
  <div class="content">菜單一<br /></div>
  <h2>第二層資訊</h2>
  <div class="content"><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /><a href="#">子功能表</a><br /></div>
  <h2>第三層資訊</h2>
  <div class="content">菜單三<br />菜單三<br />菜單三<br />菜單三<br />菜單三<br />菜單三<br /></div>
  <h2>第四層資訊</h2>
  <div class="content">子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br /></div>
  <h2>第五層資訊</h2>
  <div class="content">子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br /></div>
  <h2>第六層資訊</h2>
  <div class="content">子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br />子功能表<br

/></div>
</div>
<script type="text/javascript">
var onum=0;// 設定初始開啟的層序號
var closeState=new Array();
var ch=new Array();
function $(id){if(document.getElementById(id)){return document.getElementById(id);}else{alert("沒有找到!")}}
function $tag(id,tagName){return $(id).getElementsByTagName(tagName)}
var Ds=$tag("DoorP","div");
var Ts=$tag("DoorP","h2");
if(Ds.length != Ts.length){alert("初始化失敗!");}
function showMe(Cid,Oid){var h=parseInt(Ds[Cid].style.height);var h2=parseInt(Ds[Oid].style.height);var dH=ch[Oid];if(h>0){h=h-Math.ceil(h/3);Ds

[Cid].style.height=h+"px";};if(h2<dH){h2=h2+Math.ceil((dH-h2)/3);Ds[Oid].style.height=h2+"px";};if(h<=0&&h2>=dH){clearTimeout(closeState[Cid]);return

false;};closeState[Cid] = setTimeout("showMe("+Cid+","+Oid+")");}
for(var i=0;i<Ds.length;i++){
  ch[i]=Ds[i].offsetHeight;
  if(i==onum){Ds[i].style.height=ch[i]+"px";Ts[i].className="title01";}else{Ds[i].style.height="0px";Ts[i].className="title02";}
  Ts[i].value=i;
  Ts[i].onclick=function(){if(onum==this.value){return false;};
   Ts[onum].className="title02";
   Ts[this.value].className="title01";
   for(var i=0;i<closeState.length;i++){clearTimeout(closeState[i]);}
   showMe(onum,this.value);
   onum=this.value;
  }
}
</script>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.