<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> collision buffering Effects navigation bar </title>
<style type= "Text/css" >
* {padding:0; margin:0;}
Li {list-style:none;}
Body {background: #fff;}
UL {width:202px; margin:40px auto 0; position:relative;}
Li {width:200px; height:30px; line-height:30px; padding-left:10px; border:1px solid #ccc; border-left:3px Solid #66 6; font-size:14px; Color: #333; margin-bottom:5px; position:relative; Z-index:2; }
A {color: #333; text-decoration:none;}
. active {font-weight:bold; background: #fff0f0;}
#bar {width:10px; padding-left:0; background: #cc6699; border:1px solid #cc6699; position:absolute; top:0; Left:-14 px Z-index:3; }
</style>
<script type= "Text/javascript" >
var obj = null;
var aLis = null;
var Obar = null;
var itime = null;
var ispeed = 0;
var iAcc = 3;
var onOff = 0;
var iprev = 0;
var iNext = 0;
function Gotime () {
for (var i = 0; i < alis.length; i + = 1) {
if (alis[i] = = = This) {
var ITarget = (alis[0].offsetheight + 5) * I;
INext = i;
ONOFF = Inext-iprev;
if (itime) {
Clearinterval (itime);
}
if (onOff >= 0) {
Itime = SetInterval ("elasticity (" + ITarget + ")", 35);
}
else {
Itime = SetInterval ("Postpone (" + ITarget + ")", 35);
}
Iprev = INext;
}
Alis[i].classname = "";
This.classname = "active";
}
}
function elasticity (target) {
var top = Obar.offsettop;
Ispeed + = IACC;
Top + = Ispeed;
if (top >= target) {
Ispeed *=-0.7;
if (Math.Abs (ispeed) <= iAcc) {
Clearinterval (itime);
Itime = null;
}
top = target;
}
OBar.style.top = top + "px";
}
function postpone (target) {
if (obar.offsettop = = = target) {
Clearinterval (itime);
Itime = null;
}
else {
Ispeed = (target-obar.offsettop)/4;
OBar.style.top = obar.offsettop + ispeed + "px";
}
}
Window.onload = function () {
obj = document.getElementById ("Nav");
ALis = Obj.getelementsbytagname ("Li");
Obar = document.getElementById ("bar");
for (var i = 0; i < alis.length; i + = 1) {
if (alis[i].id! = "Bar") {
Alis[i].onmouseover = Gotime;
}
}
};
</script>
<body>
<ul id= "NAV" >
<li class= "Active" ><a href= "#" > Home </a></li>
<li><a href= "/" > Fire Academy </a></li>
<li><a href= "/" > Wonderful course </a></li>
<li><a href= "/" > Contact Us </a></li>
<li id= "Bar" ></li>
</ul>
</body>
Reproduced in original: http://www.veryhuo.com/a/view/31222.html
Collision buffering effect of the navigation bar JS