我在网上看了一个折叠菜单,很好,但是不知道其中部分代码是什么意思,谁能帮我。最好能详细注释一下,万分感激:[email protected]
<script language="JavaScript" type="text/JavaScript">
var sp=12;/*滑动的速度,单位是像素,只填写数字*//*==============
实现开关菜单的函数
=================*/
function onoff(taga)
{
var hd=taga.parentNode;
var menu = document.getElementById(hd.id+"_child");
if (menu.style.display =="none"){
taga.className= "on";
menu.style.display="";
setTimeout("slowon(\""+menu.id+"\")",5);/*hda1.style.display="none";*/}
else {
/*menu.style.height="10px";*/
/*menu.style.display="none";*/
taga.className= "off";
setTimeout("slowoff(\""+menu.id+"\")",10);
/*hda1.style.display="";*/}
}
/*================
实现菜单滑动的函数
=================*/
function slowoff(id){/*这个实现菜单收起*/
id=document.getElementById(id);
var h = parseInt(id.style.height);
if(isNaN(h))h= id.offsetHeight;
/*if (h>0){
*/
if(h-sp>0){id.style.height=(h-sp)+"px";
setTimeout("slowoff(\""+id.id+"\")",5);/*}else */}
else{id.style.height="0px";
id.style.display="none";
/*id.style.height="auto";*/}}
function slowon(id){/*这个实现菜单展开,初始条件必须是:菜单的高度="0px",不然没有效果*/
var cld;
id=document.getElementById(id);
for(i=0;i<id.childNodes.length;i++){if(id.childNodes[i].nodeType==1){cld=id.childNodes[i];break;}}
var h = id.offsetHeight;
var h1=cld.offsetHeight;
id.style.height=parseInt(id.style.height)+sp+"px";
if (h1==0 || h<h1)setTimeout("slowon(\""+id.id+"\")",5);
else{id.style.height="auto";}
}
/*=========================
在菜单载入完成后隐藏起一些菜单项
============================*/
function hidesth(){
var arr =[2,3,4,5,6,7];
for(i=0;i<arr.length;i++)
if (document.getElementById("menu"+ arr[i]+"_a")){document.getElementById("menu"+ arr[i]+"_child").style.display="none";document.getElementById("menu"+arr[i]+"_child").style.height="0px";
}
}</script>