| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4738 人关注过本帖, 1 人收藏
标题:js特效:类似QQ的菜单
只看楼主 加入收藏
小笨笨
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:1169
专家分:0
注 册:2006-4-17
收藏(1)
 问题点数:0 回复次数:25 
js特效:类似QQ的菜单

晕,不知道为什么放在代码里就不行了。大家直接用吧。


<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编辑过]

搜索更多相关主题的帖子: 特效 菜单 
2006-06-03 17:42
balaro
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-6-24
收藏
得分:0 

不错啊,收藏!!

2006-06-24 09:58
zxxlg205
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-7-15
收藏
得分:0 

厉害啊

2006-07-15 11:43
doubyue
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-7-20
收藏
得分:0 

因喜欢而选择,因选择而努力。
2006-07-20 19:46
sunangel
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-8-14
收藏
得分:0 

看看......


2006-08-22 22:27
刺鸟
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-9-14
收藏
得分:0 

太厉害了
2006-09-19 08:42
冷月清风
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-8-7
收藏
得分:0 

你过往写之,我过往看之,


轻轻的我走了,正如我轻轻的来.
2006-10-10 14:34
pippen3e
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-9
收藏
得分:0 
有个很简单的办法,我看过一个,比这个要简单的多
2006-10-11 14:37
pippen3e
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-9
收藏
得分:0 
只用一个函数就可以实现的
2006-10-11 14:38
黑色幻想
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-10-13
收藏
得分:0 

看看我的使用VBScript脚本语言写的
<HTML>
<HEAD>
<TITLE> menu </TITLE>
</HEAD>

<BODY>

<SCRIPT LANGUAGE="vbScript">
Dim layerWidth,layerHeight,titleHeight,contentHeight,itemIndex
itemIndex=1
layerWidth=120 '层的高度
layerHeight=220 '层的宽度
titleHeight=20 '标题栏的高度
contentHeight=200 '内容区的高度
temp=20 '每次移动的高度
itemCount=4 '总菜单数

Function addLayer(titleText,contentText)
Dim innerHtml
'生成每一层
innerHtml="<div id='Item" & itemIndex &"' style='top:" & temp & ";overflow:hidden;position:absolute;border-style:solid;border-color:#FF99FF;width:" & layerWidth & ";height:" & layerHeight & ";border-width:1px'><table border='0' cellpadding='0' cellspacing='0'><tr><td onclick='vbscript:changeMove(" & itemIndex & ")' style='font-size:9pt;color:#FFFFFF;background-color:#008800;width:" & layerWidth & ";height:" & titleHeight-2 & ";cursor:hand'><center>" & titleText & "</center></td></tr><tr><td style='height:1px;background-color:#FFFFFF'></td></tr><tr><td style='font-size:9pt;background-color:#eeffee;height:" & layerHeight+2 & "'>" & contentText & "</td></tr></table></div>"
Document.write(innerHtml)
itemIndex=itemIndex+1
temp=temp+20
End function


addLayer "欢迎","<BR>  欢迎光临设计在线!"
addLayer "网页陶吧","<center><a href='#'>网页工具</a> <BR><BR><a href='#'>技术平台</a> <BR><BR><a href='#'>设计理念</a> <BR><BR><a href='#'>更多</a></center>"
addLayer "美工教室","<center><a href='#'>平面设计 </a> <BR><BR><a href='#'>三维空间</a> <BR><BR><a href='#'>设计基础</a> <BR><BR><a href='#'>更多..</a></center>"
addLayer "Flash","<center><a href='#'>基础教程</a> <BR><BR><a href='#'>技巧运用</a> <BR><BR><a href='#'>实例剖析</a> <BR><BR><a href='#'>更多..</a></center>"

'使层向下移动
Function moveDown(currentItem)
Dim i
For i=currentItem To itemCount
If Document.getElementById("Item" & i).style.height<>"20px" And i<>1 then
Document.getElementById("Item" & i).style.top=CInt(Replace(Document.getElementById("Item" & i).style.top,"px",""))+contentHeight
Document.getElementById("Item" & i).style.height="20px"
End if
next
End Function

'使层向上移动
Function moveUp(currentItem)
Dim i
For i=currentItem To 1 Step -1
If Document.getElementById("Item" & i).style.height<>"220px" then
Document.getElementById("Item" & i).style.top=CInt(Replace(Document.getElementById("Item" & i).style.top,"px",""))-contentHeight
Document.getElementById("Item" & i).style.height=layerheight
End if
next
End Function

Function changeMove(currentItem)
'MsgBox Document.getElementById("Item" & currentItem).style.height
If Document.getElementById("Item" & currentItem).style.height="220px" Then
moveDown(currentItem)
Else
moveUp(currentItem)
End If
End Function
moveDown(1)

</SCRIPT>
</BODY>
</HTML>


我爱学习!
2006-10-14 19:51
快速回复:js特效:类似QQ的菜单
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016615 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved