【转载】JS实现弹性菜单效果
来源:互联网 发布:iphone连接电脑软件 编辑:程序博客网 时间:2024/05/21 22:47
在线演示地址如下:
http://demo.jb51.net/js/2015/js-tx-move-menu-style-codes/
具体代码如下:
<!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, ul, ol, dl, dt, dd, h1, h2, h3, h4, h5, p, form { padding: 0; margin: 0; }
li { list-style: none; }
img { border: 0; }
body { font-family: Arial; background:
#fff url() repeat-x; }
#header { width: 960px; height: 107px; margin: 0 auto 12px; position: relative; }
#header h1 { padding-top: 15px; float: left; }
#header ul { height: 44px; position: absolute; right: 0; bottom: 0; }
#header .normal, #header .active { float: left; width: 88px; height: 44px; position: relative; z-index: 1; }
#header .normal a, #header .active a { float: left; width: 88px; height: 44px; line-height: 44px; text-align: center; text-decoration: none; font-size: 14px; font-weight: bold; }
#header .active a { color: #fff; }
#header .normal a { color: #999; }
#btn_bg { width: 88px; height: 44px; background: #fb2347 url(); position: absolute; overflow:hidden; left: 608px; bottom: 0; z-index: 2; }
#btn_bg ul { width: 528px; left:-176px; position:absolute; }
</style>
<script type=
"text/javascript"
>
var
away;
window.onload=
function
()
{
var
odiv=document.getElementById(
"btn_bg"
);
var
oul=odiv.getElementsByTagName(
"ul"
)[0];
var
oli=document.getElementById(
"header"
).getElementsByTagName(
"ul"
)[0].getElementsByTagName(
"li"
);
var
i=0;
for
(i=0;i<oli.length;i++)
{
oli[i].index=i;
oli[i].onmouseover=
function
()
{
away=432+88*
this
.index;
menuInterval();
};
};
}
var
timer=
null
;
function
menuInterval()
{
if
(timer)
{
clearInterval(timer);
}
timer=setInterval(menuMove, 30);
}
var
step=0;
var
l=0;
function
menuMove()
{
var
odiv=document.getElementById(
"btn_bg"
);
var
oul=odiv.getElementsByTagName(
"ul"
)[0];
step+=(away-odiv.offsetLeft)/10;
step=step*0.78;
l=parseInt(odiv.offsetLeft+step);
odiv.style.left=l+
"px"
;
oul.style.left=-l+432+
"px"
;;
}
</script>
</head>
<body>
<div id=
"header"
>
<ul>
<li class=
"normal"
><a href=
"#"
>首页</a></li>
<li class=
"normal"
><a href=
"#"
>叶子课程</a></li>
<li class=
"normal"
><a href=
"#"
>叶子资源</a></li>
<li class=
"normal"
><a href=
"#"
>留言</a></li>
<li class=
"normal"
><a href=
"#"
>叶子博客</a></li>
<li class=
"normal"
><a href=
"#"
>联系叶子</a></li>
</ul>
<div id=
"btn_bg"
>
<ul>
<li class=
"active"
><a href=
"#"
>首页</a></li>
<li class=
"active"
><a href=
"#"
>叶子课程</a></li>
<li class=
"active"
><a href=
"#"
>叶子资源</a></li>
<li class=
"active"
><a href=
"#"
>留言</a></li>
<li class=
"active"
><a href=
"#"
>叶子博客</a></li>
<li class=
"active"
><a href=
"#"
>联系叶子</a></li>
</ul>
</div>
</div>
</body>
</html>
0 0
- 【转载】JS实现弹性菜单效果
- js-弹性点击菜单
- js实现树形菜单效果
- js实现导航菜单效果
- 使用js实现OICQ菜单效果
- 用js枚举实现简易菜单效果
- js实现下拉菜单动画效果
- 自定义ScrollView实现弹性效果
- 继承ListView实现弹性效果
- 转载一个js实现div拖动效果
- 【转载】js实现产品放大镜展示效果
- 【转载】JS实现淘宝 放大镜效果
- js之导航栏目弹性运动效果
- svg动画实现弹性侧栏菜单
- js菜单效果
- js菜单效果
- Android 实现ListView的弹性效果
- 微信较完美实现禁止下拉弹性效果
- 正则表达式的基本语法规则
- 判断两个矩形是否相交的4个方法
- js里function前面加!
- 十大基于Docker的开发工具
- 单个进程最大线程数
- 【转载】JS实现弹性菜单效果
- 小心浏览器的重定向缓存 REDIRECT CACHE
- 励精图治---Concurrency---ThreadPoolExecutor最详
- jquery使用心得
- Cocoapods的安装和使用详解
- android studio 删除项目 (delete a module)的方法
- IBM X3650 M4安装win 2008 Server操作指南
- Android UI 之ToggleTextView的妙用(自定义可切换TextView)
- mysql备份之xtrabackup