晕,不知道为什么放在代码里就不行了。大家直接用吧。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
//该函数在调用过程中只需要在将要点击的单元格内的onclick事件中调用showme函数即可
//function showme(obj1, obj2)该函数主要为使点击的对象高亮度显示,并调用moveme函数,参数obj1为母体即<div>标签的id,obj2为点击对象本身
//function moveme(obj)该函数判断单元的移动,并调用相应的函数处理,obj参数为母体
//function moveup(obj,objtop)该函数使一个单元向上移动,参数obj为母体,objtop为母体的本身最高高度
//function movedown(obj,objbuttom)该函数使一个单元向下移动,参数obj为母体,objbuttom为母体的本身最低高度
var headHeight = 22;//每个标题的高度
var bodyHeight = 160;//母体高度
var objcount = 4;//组的个数
var step = 3;//移动速度(请确认可以被'bodyHeight-headHeight'整除,当前的设定可选速度为1,2,3,6,23,138)
function showme(obj1, obj2)
{
//以下循环为改变标题的背景颜色
for(i=0;i<document.all.tags("td").length;i++)
{
if (document.all.tags("td")[i].className == 'headtd')
document.all.tags("td")[i].bgColor = '#0099FF';
}
obj2.bgColor = '#00BBFF';
moveme(obj1);
}
function moveme(obj)
{
idnumber = parseInt(obj.id.substr(4));
objtop = headHeight * (idnumber - 1);
objbuttom = bodyHeight + headHeight * (idnumber - 2);
currenttop = parseInt(obj.style.top);
if (currenttop >= objbuttom)
{
//检验出每一个应该向上移动的层
countid = 1;
for(i=0;i<document.all.tags("div").length;i++)
{
if (document.all.tags("div")[i].id == 'item'+countid+'body')
{
obj = document.all.tags("div")[i];
objtop = headHeight * (countid - 1);
moveup(obj,objtop);
if (countid == idnumber)
break;
countid++;
}
}
}
else if ((currenttop <= objtop) && (idnumber < objcount))
{
//检验出每一个应该向下移动的层
idnumber++;
countid = objcount;
for(i=document.all.tags("div").length-1;i>=0;i--)
{
if (document.all.tags("div")[i].id == 'item'+countid+'body')
{
obj = document.all.tags("div")[i];
objbuttom = bodyHeight + headHeight * (countid - 2);
movedown(obj,objbuttom);
if (countid == idnumber)
break;
countid--;
}
}
}
}
function moveup(obj,objtop)
{
currenttop = parseInt(obj.style.top);
if (currenttop > objtop)
{
obj.style.top = currenttop - step;
window.setTimeout('moveup('+obj.id+','+objtop+')',1)
}
}
function movedown(obj,objbuttom)
{
currenttop = parseInt(obj.style.top);
if (currenttop < objbuttom)
{
obj.style.top = currenttop + step;
window.setTimeout('movedown('+obj.id+','+objbuttom+')',1)
}
}
// -->
</script>
<style type="text/css">
<!--
.headtd { border: 2px outset; border-color: #00bbFF #0077FF #0077FF #00bbFF; cursor: hand; font-size: 9pt}
.bodytd { background: #0099FF; border: 2px outset; border-color: #0099FF #0077FF #0077FF #00bbFF; font-size: 9pt}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="mainboard" style="position:absolute; left:2px; top:2px; width:120px; height:226px; z-index:3; overflow: hidden; background-color: #0099FF;">
<div id="item1body" style="position:absolute; left:0; top:0; width:120px; height:160px; z-index:1; overflow: hidden">
<table width="100%" border="0" height="100%" cellpadding="2" cellspacing="0">
<tr>
<td id="item1head" height="20" class="headtd" onclick="showme(item1body,this)" bgcolor="#0099FF">
<div align="center">第一级</div>
</td>
</tr>
<tr>
<td class="bodytd">
<div align="center">123</div>
</td>
</tr>
</table>
</div>
<div id="item2body" style="position:absolute; left:0px; top:160; width:120; height:160; z-index:2; overflow: hidden">
<table width="100%" border="0" height="100%" cellpadding="2" cellspacing="0">
<tr>
<td id="item2head" height="20" class="headtd" onclick="showme(item2body,this)" bgcolor="#0099FF">
<div align="center">第二级</div>
</td>
</tr>
<tr>
<td class="bodytd">
<div align="center">456</div>
</td>
</tr>
</table>
<p class="headtd"> </p>
</div>
<div id="item3body" style="position:absolute; left:0; top:182; width:120px; height:160; z-index:3">
<table width="100%" border="0" height="100%" cellpadding="2" cellspacing="0">
<tr>
<td id="item3head" height="20" class="headtd" onclick="showme(item3body,this)" bgcolor="#0099FF">
<div align="center">第三级</div>
</td>
</tr>
<tr>
<td class="bodytd">
<div align="center">789</div>
</td>
</tr>
</table>
</div>
<div id="item4body" style="position:absolute; left:0; top:204; width:120px; height:160; z-index:4; overflow: hidden">
<table width="100%" border="0" height="100%" cellpadding="2" cellspacing="0">
<tr>
<td id="item4head" height="20" class="headtd" onclick="showme(item4body,this)" bgcolor="#0099FF">
<div align="center">第四级</div>
</td>
</tr>
<tr>
<td class="bodytd">
<div align="center">000</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
[此贴子已经被作者于2006-6-3 17:44:44编辑过]