分类分类
更新时间:2015-08-03 14:50作者:fang
本文实例讲述了javascript实现超炫的向上滑行菜单。分享给大家供大家参考。具体如下:
<!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=UTF-8" />
<title>JS实现文字上下滑动导航</title>
<style type="text/css">
body { margin:0; background:#66FF99; }
ul { padding-left:0; margin:0; }
li { list-style:none; }
#nav { height:40px; background:#900; margin-top:50px; }
#nav ul { width:240px; height:40px; margin:0 auto; }
#nav li {height:40px; width:240px;}
#nav a { float:left; width:240px;position:relative; height:40px; overflow:hidden; font-size:14px; color:#e0e03a; text-decoration:none; cursor:pointer; }
#nav strong { float:left;width:240px; }
#nav span { float:left;width:200px; padding:0 20px; height:40px; line-height:40px; background:#900; clear:both; white-space:nowrap;}
#nav .active,#nav .current span { background:#600; color:#fff; }
#nav .current .active { color:#e0e03a; }
</style>
<script>
window.onload=function()
{
var oDiv=document.getElementById('nav');
var aStrong=oDiv.getElementsByTagName('strong');
var aA=oDiv.getElementsByTagName('a');
var iTarget=oDiv.getElementsByTagName('li')[0].offsetHeight;
for(var i=0; i<aStrong.length; i++)
{
aA[i].style.width=aStrong[i].style.width=aStrong[i].getElementsByTagName('span')[0].offsetWidth+'px';
aStrong[i].style.position='absolute';
aStrong[i].style.top=aStrong[i].style.left=0;
aStrong[i].onmouseover=function()
{
startMove(this, -iTarget);
};
aStrong[i].onmouseout=function()
{
startMove(this, 0);
};
}
};
function startMove(obj,target)
{
clearInterval(obj.iTime);
obj.iTime=setInterval(function(){
if(obj.offsetTop==target)
{
clearInterval(obj.iTime);
}
else
{
var iSpeed=(target-obj.offsetTop)/4;
iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
obj.style.top=obj.offsetTop+iSpeed+'px';
}
}, 30);
}
</script>
</head>
<body>
<div id="nav">
<ul>
<li class="current">
<a href="#">
<strong>
<span>首页</span>
<span class="active">首页</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>前端开发课程</span>
<span class="active">前端开发课程</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>妙味视频教程</span>
<span class="active">妙味视频教程</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>周末班上课安排</span>
<span class="active">周末班上课安排</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>结课标准</span>
<span class="active">结课标准</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>联系妙味</span>
<span class="active">联系妙味</span>
</strong>
</a>
</li>
</ul>
</div>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
相关
纸片马里奥(Paperboat)角色扮演107.85 MBv1.0.32026-11-29
下载cyime输入法实用工具74.58 MBv1.15.1072026-11-29
下载武道仙宗官方版角色扮演456.19 Mv1.0.02026-11-29
下载mmrl模块app实用工具7.15 Mv342962026-11-29
下载零希沃特手机版角色扮演511.54 Mv1.4.22026-11-29
下载Bannerlator手游辅助574.84 MBv3.2.12026-11-29
下载巅峰激战(魔幻格斗游戏)动作射击797.1 MBv1.0.92026-11-29
下载我的火车防御策略游戏181.87 Mv1.1.52026-11-29
下载三国棋逢对手角色扮演1.7Gv1.2.5.0002.1125.11432026-11-29
下载图纸没问题手机版休闲益智78.41 Mv1.0.182026-11-29
下载蛊界永生角色扮演407.01 Mv0.4.162026-11-28
下载百炼仙途角色扮演528.9 Mv10002026-11-28
下载










