应该能完成你的要求,带滚动效果,速度可调。<HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- ********************************************************** -->
<!-- 本代码中的菜单均为层的形式,浮在其他HTML代码上方,建议 -->
<!-- 将网页做成分帧的方式,本菜单作为导航帧,可以保证显示正确。 -->
<!-- 如果必须使用一个页面,可以使用表格,在导航条的位置处划出一 -->
<!-- 块足够大的空白区域不要填写内容。 -->
<!-- -->
<!-- 作者:qiangsheng;电子邮件:[email protected] -->
<!-- 转载使用请保留上述信息,谢谢。 -->
<!-- ********************************************************** --><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>移动的菜单</title>
<style type="text/css">
a
{
font-family:宋体;
font-size:13px
}
a:link, a:visited
{
color:#600000;
text-decoration:none
}
a:active, a:hover
{
color:#600000;
text-decoration:underline;
font-weight:bold
}
td
{
font-family:宋体;
font-size:12px;
}
</style>
</head><BODY bgcolor="#FFFDDF"><SCRIPT language=JavaScript>
//定义全局变量//菜单项的数量
var MaxFatherMenu = 0; //父菜单项的个数,初始值为0,菜单完全建立后的值为主菜单项的个数
MaxSonMenu = new Array(); //子菜单的个数,对应于每个主菜单项//菜单项的位置和大小
MenuTop = new Array(); //每个父菜单项的顶端位置
MenuTop[0] = 0; //这个只作为参照物,由它确定第一个父菜单项的顶端位置
MenuLeft = 0; //菜单项的左端位置
FatherMenuHeight = 30; //父菜单项的高度
SonMenuHeight = 24; //子菜单项的高度
MenuWidth = 120; //菜单项的宽度//菜单项移动时的位置
MenuHeight = new Array(); //每个子菜单的总高度
MenuPos = new Array(); //每次移动后的父菜单位置//菜单项对应的对象号
FatherMenuIndex = new Array(); //父菜单的对象号
SonMenuIndex = new Array(); //子菜单的对象号//菜单移动的速度
var LenPerMove = 4;
var TimePerMove = 10;//到达指定位置的菜单,0为未到达,1为到达
InPos = new Array();//设置菜单项的内容
//以空字符串""作为段分隔,每段第一个为父菜单项,后面为子菜单项
//全部菜单定义完后要用两个""结束
//每个菜单项必须是一段封闭的html代码,其中父菜单项不能有链接
AllMenu = new Array(
"<img src='menu-denglu.gif' border='0'>",
"<a href='ArticleEdit.jsp' target='mainFrame'>录入</a>",
"<a href='ArticleManage.jsp' target='mainFrame'>审核</a>",
"<a href='StorageInput.jsp' target='mainFrame'>编辑</a>",
"<a href='MediaInput.jsp' target='mainFrame'>多媒体</a>",
"",
"<img src='menu-jiansuo.gif' border=0>",
"<a href='ArticleQuery.jsp' target='mainFrame'>检索</a>",
"<a href='StorageQuery.jsp' target='mainFrame'>保管</a>",
"",
"<img src='menu-tongji.gif' border=0>",
"<a href='StatisticResult.jsp' target='mainFrame'>统计</a>",
"<a href='StatisticResult.jsp' target='mainFrame'>保管</a>",
"<a href='StatisticResult.jsp' target='mainFrame'>系统</a>",
"",
"<img src='#sResourcePath#menu-guanbi.gif' border=0>",
"",
"")</SCRIPT><SCRIPT language=JavaScript>initMenu()function initMenu()
{
var MenuNum = 0;
var newItem = AllMenu[MenuNum]; while (newItem != "")
{
//设置父菜单项 MaxFatherMenu ++; //父菜单个数加一
MaxSonMenu[MaxFatherMenu] = 0; //子菜单个数清零
MenuTop[MaxFatherMenu] = MenuTop[MaxFatherMenu - 1] + FatherMenuHeight; //下一个菜单位置增加
MenuPos[MaxFatherMenu] = MenuTop[MaxFatherMenu]; //id=FML为父菜单的层,后面是该层的编号
document.write('<div id="FML' + MaxFatherMenu + '" style="position:absolute;overflow:hidden;top:' + MenuTop[MaxFatherMenu] + ';left:' + MenuLeft + ';width:' + MenuWidth + '">')
document.write('<div style="position:absolute;top:0;left:0;width:' + MenuWidth + '">');
document.write('<table align="center" border="0" cellpadding="0" cellspacing="0">');
document.write('<tr><td align="center"><a href="javascript:do_m_ie(' + MaxFatherMenu + ')">' + newItem + '</a></td></tr>');
document.write('</table>');
document.write('</div>'); //id=SML为子菜单的层,后面是该层的编号
document.write('<div id="SML' + MaxFatherMenu + '" style="position:absolute;top:' + FatherMenuHeight + ';left:0;width:' + MenuWidth + '">');
document.write('<table align="center" border="0" cellpadding="0" cellspacing="0" width="' + MenuWidth + '" background="#sResourcePath#menu-mspace.gif">');
document.write('<tr><td><img src="#sResourcePath#menu-tspace.gif" height="15"></td></tr>');
MenuNum ++;
newItem = AllMenu[MenuNum];
while (newItem != "")
{
//设置子菜单项
MaxSonMenu[MaxFatherMenu] ++; //子菜单个数加一 document.write('<tr><td align="center" height="' + SonMenuHeight + '">' + newItem + '</td></tr>'); //继续读下一子菜单项
MenuNum ++;
newItem = AllMenu[MenuNum];
}
//结束设置子菜单项
document.write('<tr><td><img src="#sResourcePath#menu-bspace.gif" height="15"></td></tr>');
document.write('</table>');
document.write('</div>'); //结束设置父菜单项
document.write('</div>'); //继续读下一个父菜单项
MenuNum ++;
newItem = AllMenu[MenuNum];
} //做一些为产生动态效果的准备工作
var i;
for (i = 1; i < MaxFatherMenu; i++)
{
//初始化菜单的高度,这个高度为子菜单再加一个小的间隔。
MenuHeight[i] = MaxSonMenu[i] * SonMenuHeight + 30;
}
MenuHeight[MaxFatherMenu] = MaxSonMenu[MaxFatherMenu] * SonMenuHeight; //找到各菜单层对应的对象号,为移动菜单做准备
var PageObjects = document.all.length;
var SMI = 1, FMI = 1;
for (i = 0; i < PageObjects; i++)
{
if (document.all[i].id.substring(0,3) == "SML")
{
SonMenuIndex[SMI] = i;
SMI ++;
}
if (document.all[i].id.substring(0,3) == "FML")
{
FatherMenuIndex[FMI] = i;
FMI ++;
}
}
document.all[FatherMenuIndex[MaxFatherMenu]].style.height = FatherMenuHeight;}
function do_m_ie(MenuToMove) //MenuToMove为点击的父菜单项的编号
{
var i; //计算将要移动到的位置
for (i = 1; i <= MaxFatherMenu; i++)
{
MenuTop[i] = MenuTop[i - 1] + FatherMenuHeight;
if (i - 1 == MenuToMove)
MenuTop[i] += MenuHeight[i - 1];
} //移动菜单
for (i = 1; i <= MaxFatherMenu; i++)
InPos[i] = 0;
m_move_ie();}
function m_move_ie()
{
//找到各菜单层对应的对象号,为移动菜单做准备
var i, InPosNum = 0;
for (i = 1; i <= MaxFatherMenu; i++)
{
if (MenuTop[i] > MenuPos[i])
{
//菜单的位置高于目标位置
MenuPos[i] = MenuPos[i] + LenPerMove;
if (Math.abs(MenuTop[i] - MenuPos[i]) < LenPerMove)
{
MenuPos[i] = MenuTop[i];
InPos[i] = 1;
}
document.all[FatherMenuIndex[i]].style.top = MenuPos[i];
}
else if (MenuTop[i] < MenuPos[i])
{
//菜单的位置低于目标位置
MenuPos[i] = MenuPos[i] - LenPerMove;
if (Math.abs(MenuTop[i] - MenuPos[i]) < LenPerMove)
{
MenuPos[i] = MenuTop[i];
InPos[i] = 1;
}
document.all[FatherMenuIndex[i]].style.top = MenuPos[i];
}
else
{
InPos[i] = 1;
}
InPosNum += InPos[i];
}
for (i = 1; i < MaxFatherMenu; i++)
{
document.all[FatherMenuIndex[i]].style.height = MenuPos[i+1] - MenuPos[i];
} if (InPosNum < MaxFatherMenu)
setTimeout("m_move_ie()", TimePerMove);
} //如果需要打开页面时就打开某个菜单,可以使用下面的代码
var OpenNum = MaxFatherMenu; //把MaxFatherMenu替换成需要打开的菜单号
document.write('<scr' + 'ipt>');
document.write('javascript:do_m_ie(' + OpenNum + ')');
document.write('</scr' + 'ipt>');</SCRIPT></BODY>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- ********************************************************** -->
<!-- 本代码中的菜单均为层的形式,浮在其他HTML代码上方,建议 -->
<!-- 将网页做成分帧的方式,本菜单作为导航帧,可以保证显示正确。 -->
<!-- 如果必须使用一个页面,可以使用表格,在导航条的位置处划出一 -->
<!-- 块足够大的空白区域不要填写内容。 -->
<!-- -->
<!-- 作者:qiangsheng;电子邮件:[email protected] -->
<!-- 转载使用请保留上述信息,谢谢。 -->
<!-- ********************************************************** --><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>移动的菜单</title>
<style type="text/css">
a
{
font-family:宋体;
font-size:13px
}
a:link, a:visited
{
color:#600000;
text-decoration:none
}
a:active, a:hover
{
color:#600000;
text-decoration:underline;
font-weight:bold
}
td
{
font-family:宋体;
font-size:12px;
}
</style>
</head><BODY bgcolor="#FFFDDF"><SCRIPT language=JavaScript>
//定义全局变量//菜单项的数量
var MaxFatherMenu = 0; //父菜单项的个数,初始值为0,菜单完全建立后的值为主菜单项的个数
MaxSonMenu = new Array(); //子菜单的个数,对应于每个主菜单项//菜单项的位置和大小
MenuTop = new Array(); //每个父菜单项的顶端位置
MenuTop[0] = 0; //这个只作为参照物,由它确定第一个父菜单项的顶端位置
MenuLeft = 0; //菜单项的左端位置
FatherMenuHeight = 30; //父菜单项的高度
SonMenuHeight = 24; //子菜单项的高度
MenuWidth = 120; //菜单项的宽度//菜单项移动时的位置
MenuHeight = new Array(); //每个子菜单的总高度
MenuPos = new Array(); //每次移动后的父菜单位置//菜单项对应的对象号
FatherMenuIndex = new Array(); //父菜单的对象号
SonMenuIndex = new Array(); //子菜单的对象号//菜单移动的速度
var LenPerMove = 4;
var TimePerMove = 10;//到达指定位置的菜单,0为未到达,1为到达
InPos = new Array();//设置菜单项的内容
//以空字符串""作为段分隔,每段第一个为父菜单项,后面为子菜单项
//全部菜单定义完后要用两个""结束
//每个菜单项必须是一段封闭的html代码,其中父菜单项不能有链接
AllMenu = new Array(
"<img src='menu-denglu.gif' border='0'>",
"<a href='ArticleEdit.jsp' target='mainFrame'>录入</a>",
"<a href='ArticleManage.jsp' target='mainFrame'>审核</a>",
"<a href='StorageInput.jsp' target='mainFrame'>编辑</a>",
"<a href='MediaInput.jsp' target='mainFrame'>多媒体</a>",
"",
"<img src='menu-jiansuo.gif' border=0>",
"<a href='ArticleQuery.jsp' target='mainFrame'>检索</a>",
"<a href='StorageQuery.jsp' target='mainFrame'>保管</a>",
"",
"<img src='menu-tongji.gif' border=0>",
"<a href='StatisticResult.jsp' target='mainFrame'>统计</a>",
"<a href='StatisticResult.jsp' target='mainFrame'>保管</a>",
"<a href='StatisticResult.jsp' target='mainFrame'>系统</a>",
"",
"<img src='#sResourcePath#menu-guanbi.gif' border=0>",
"",
"")</SCRIPT><SCRIPT language=JavaScript>initMenu()function initMenu()
{
var MenuNum = 0;
var newItem = AllMenu[MenuNum]; while (newItem != "")
{
//设置父菜单项 MaxFatherMenu ++; //父菜单个数加一
MaxSonMenu[MaxFatherMenu] = 0; //子菜单个数清零
MenuTop[MaxFatherMenu] = MenuTop[MaxFatherMenu - 1] + FatherMenuHeight; //下一个菜单位置增加
MenuPos[MaxFatherMenu] = MenuTop[MaxFatherMenu]; //id=FML为父菜单的层,后面是该层的编号
document.write('<div id="FML' + MaxFatherMenu + '" style="position:absolute;overflow:hidden;top:' + MenuTop[MaxFatherMenu] + ';left:' + MenuLeft + ';width:' + MenuWidth + '">')
document.write('<div style="position:absolute;top:0;left:0;width:' + MenuWidth + '">');
document.write('<table align="center" border="0" cellpadding="0" cellspacing="0">');
document.write('<tr><td align="center"><a href="javascript:do_m_ie(' + MaxFatherMenu + ')">' + newItem + '</a></td></tr>');
document.write('</table>');
document.write('</div>'); //id=SML为子菜单的层,后面是该层的编号
document.write('<div id="SML' + MaxFatherMenu + '" style="position:absolute;top:' + FatherMenuHeight + ';left:0;width:' + MenuWidth + '">');
document.write('<table align="center" border="0" cellpadding="0" cellspacing="0" width="' + MenuWidth + '" background="#sResourcePath#menu-mspace.gif">');
document.write('<tr><td><img src="#sResourcePath#menu-tspace.gif" height="15"></td></tr>');
MenuNum ++;
newItem = AllMenu[MenuNum];
while (newItem != "")
{
//设置子菜单项
MaxSonMenu[MaxFatherMenu] ++; //子菜单个数加一 document.write('<tr><td align="center" height="' + SonMenuHeight + '">' + newItem + '</td></tr>'); //继续读下一子菜单项
MenuNum ++;
newItem = AllMenu[MenuNum];
}
//结束设置子菜单项
document.write('<tr><td><img src="#sResourcePath#menu-bspace.gif" height="15"></td></tr>');
document.write('</table>');
document.write('</div>'); //结束设置父菜单项
document.write('</div>'); //继续读下一个父菜单项
MenuNum ++;
newItem = AllMenu[MenuNum];
} //做一些为产生动态效果的准备工作
var i;
for (i = 1; i < MaxFatherMenu; i++)
{
//初始化菜单的高度,这个高度为子菜单再加一个小的间隔。
MenuHeight[i] = MaxSonMenu[i] * SonMenuHeight + 30;
}
MenuHeight[MaxFatherMenu] = MaxSonMenu[MaxFatherMenu] * SonMenuHeight; //找到各菜单层对应的对象号,为移动菜单做准备
var PageObjects = document.all.length;
var SMI = 1, FMI = 1;
for (i = 0; i < PageObjects; i++)
{
if (document.all[i].id.substring(0,3) == "SML")
{
SonMenuIndex[SMI] = i;
SMI ++;
}
if (document.all[i].id.substring(0,3) == "FML")
{
FatherMenuIndex[FMI] = i;
FMI ++;
}
}
document.all[FatherMenuIndex[MaxFatherMenu]].style.height = FatherMenuHeight;}
function do_m_ie(MenuToMove) //MenuToMove为点击的父菜单项的编号
{
var i; //计算将要移动到的位置
for (i = 1; i <= MaxFatherMenu; i++)
{
MenuTop[i] = MenuTop[i - 1] + FatherMenuHeight;
if (i - 1 == MenuToMove)
MenuTop[i] += MenuHeight[i - 1];
} //移动菜单
for (i = 1; i <= MaxFatherMenu; i++)
InPos[i] = 0;
m_move_ie();}
function m_move_ie()
{
//找到各菜单层对应的对象号,为移动菜单做准备
var i, InPosNum = 0;
for (i = 1; i <= MaxFatherMenu; i++)
{
if (MenuTop[i] > MenuPos[i])
{
//菜单的位置高于目标位置
MenuPos[i] = MenuPos[i] + LenPerMove;
if (Math.abs(MenuTop[i] - MenuPos[i]) < LenPerMove)
{
MenuPos[i] = MenuTop[i];
InPos[i] = 1;
}
document.all[FatherMenuIndex[i]].style.top = MenuPos[i];
}
else if (MenuTop[i] < MenuPos[i])
{
//菜单的位置低于目标位置
MenuPos[i] = MenuPos[i] - LenPerMove;
if (Math.abs(MenuTop[i] - MenuPos[i]) < LenPerMove)
{
MenuPos[i] = MenuTop[i];
InPos[i] = 1;
}
document.all[FatherMenuIndex[i]].style.top = MenuPos[i];
}
else
{
InPos[i] = 1;
}
InPosNum += InPos[i];
}
for (i = 1; i < MaxFatherMenu; i++)
{
document.all[FatherMenuIndex[i]].style.height = MenuPos[i+1] - MenuPos[i];
} if (InPosNum < MaxFatherMenu)
setTimeout("m_move_ie()", TimePerMove);
} //如果需要打开页面时就打开某个菜单,可以使用下面的代码
var OpenNum = MaxFatherMenu; //把MaxFatherMenu替换成需要打开的菜单号
document.write('<scr' + 'ipt>');
document.write('javascript:do_m_ie(' + OpenNum + ')');
document.write('</scr' + 'ipt>');</SCRIPT></BODY>
</HTML>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货