1 |
- function sNav(k){var f=this;var b=f.getByClass(document,k)[0];var l=b.getElementsByTagName("li");this.aHoverItem=[];this.aA=b.getElementsByTagName("a");for(var e=0;e<l.length;e++){var g=l[e].offsetWidth;var d=b.offsetHeight;var j={"top":f.getStyle(l[e],"paddingTop"),"right":f.getStyle(l[e],"paddingRight"),"bottom":f.getStyle(l[e],"paddingBottom"),"left":f.getStyle(l[e],"paddingBottom")};var c=document.createElement("span");this.aHoverItem.push(c);var a=document.createElement("div");this.aA[e].appendChild(a);a.appendChild(c);a.appendChild(l[e]);a.style.position="absolute";a.style.background="#fff";this.aA[e].style.width=g+"px";this.aA[e].style.height=d+"px";a.style.top=-d+"px";a.slideHeight=d;l[e].style.padding="0";l[e].style.lineHeight=d+"px";c.style.height=d+"px";c.style.width=g+"px";c.style.display="block";c.style.lineHeight=d+"px";c.innerHTML=this.hoverText?this.hoverText:l[e].innerHTML;function h(i){f.myAddEvent(i,"mouseover",function(m){f.hoverIn(m,i)});f.myAddEvent(i,"mouseout",function(m){f.hoverOut(m,i)})}h(a)}this.slideSpeed=8}sNav.prototype.setText=function(b){for(var a in b){this.aHoverItem[a].innerHTML=b[a]}};sNav.prototype.hoverIn=function(a,b){this.startMove(b,{"top":0})};sNav.prototype.hoverOut=function(a,b){this.startMove(b,{"top":-b.slideHeight})};sNav.prototype.startMove=function(f,c,d){var h;var e;var a=this.slideSpeed;var b=20;var g=this;clearInterval(f.moveTimer);f.moveTimer=setInterval(function(){var j=true;for(var i in c){var l=g.getStyle(f,i);var k=c[i];h=parseInt(l,10);if(h!=k){j=false}if(j){clearInterval(f.moveTimer);d&&d()}else{e=(k-h)/a;e=k>h?Math.ceil(e):Math.floor(e);f.style[i]=(h+e)+"px"}}},b)};sNav.prototype.myAddEvent=function(c,a,b){if(c.attachEvent){c.attachEvent("on"+a,function(){b.call(this)})}else{c.addEventListener(a,b,false)}};sNav.prototype.getByClass=function(e,d){var f=[];var a=e.getElementsByTagName("*");var c=new RegExp("\\b"+d+"\\b",b);for(var b=0;b<a.length;b++){if(c.test(a[b].className)){f.push(a[b])}}return f};sNav.prototype.getStyle=function(c,a){var b;if(window.getComputedStyle){b=getComputedStyle(c,false)[a]}else{b=c.currentStyle[a]}b=parseInt(b,10);return b};
|