不少朋友通过各种方式问我要Blog顶部的滚动导航菜单的代码。其实也没什么特别的,但既然有需求,我就还是把这部分代码整理出来,供大家参考。
复制代码 代码如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>FloatDiv</TITLE>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<styletype="text/css">
#zealNavigatorBar{
position:absolute;
z-index:100;
width:760px;
height:32px;
line-height:32px;
top:0px;
left:0px;
padding:0px;
margin:0px;
border-bottom:1pxsolid#646465;
background-color:#C0C0C3;
}
</style>
</HEAD>
<BODY>
<divid=zealNavigatorBar>
<ahref="/">Anythinghere</a>
<ahref="/">Anythinghere</a>
<ahref="/">Anythinghere</a>
</div>
<scriptlanguage="JavaScript">
for(vart=0;t<1000;t++)document.writeln('Testcontent:line'+t+'<br/>');
</script>
<scriptlanguage="JavaScript">
varg_myBodyInstance=document.body;
varg_myBodyInstanceString="document.body";
if(document.compatMode!="BackCompat"){
//forlooser.dtd
g_myBodyInstance=document.documentElement;
g_myBodyInstanceString="document.documentElement";
}
varisMinNS4=(navigator.appName.indexOf("Netscape")>=0&&
parseFloat(navigator.appVersion)>=4)?1:0;
varisMinNS5=(navigator.appName.indexOf("Netscape")>=0&&
parseFloat(navigator.appVersion)>=5)?1:0;
varisMinIE4=(document.all)?1:0;
varisMinIE5=(isMinIE4&&navigator.appVersion.indexOf("5.")>=0)?1:0;
varisMacIE=(isMinIE4&&navigator.userAgent.indexOf("Mac")>=0)?1:0;
vargetFFVersion=navigator.userAgent.substring(
navigator.userAgent.indexOf("Firefox")).split("/")[1];
//extraheightinpxtoaddtoiframeinFireFox1.0+browsers
varFFextraHeight=getFFVersion<1.5?16:0;
functiongetLayer(name){
if(isMinNS5)
returndocument.getElementById(name);
elseif(isMinIE4)
returneval('document.all.'+name);
elseif(isMinNS4)
returnfindLayer(name,document);
returnnull;
}
functionfindLayer(name,doc){
vari,layer;
for(i=0;i<doc.layers.length;i++){
layer=doc.layers[i];
if(layer.name==name)
returnlayer;
if(layer.document.layers.length>0){
layer=findLayer(name,layer.document);
if(layer!=null)
returnlayer;
}
}
returnnull;
}
functionmoveLayerTo(layer,x,y){
if(isMinIE4){
layer.style.left=x;
layer.style.top=y;
}
elseif(isMinNS5){
layer.style.left=x+'px';
layer.style.top=y+'px';
}
elseif(isMinNS4)
layer.moveTo(x,y);
}
functiongetPageLeft(layer){
if(isMinIE4||isMinNS5)
return(layer.offsetLeft);
elseif(isMinNS4)
return(layer.pageX);
return(-1);
}
functiongetPageTop(layer){
if(isMinIE4||isMinNS5)
return(layer.offsetTop);
elseif(isMinNS4)
return(layer.pageY);
return(-1);
}
functiongetPageScrollX(){
if(isMinIE4||isMinNS5)
return(g_myBodyInstance.scrollLeft);
elseif(isMinNS4)
return(window.pageXOffset);
return(-1);
}
functiongetPageScrollY(){
if(isMinIE4||isMinNS5)
return(g_myBodyInstance.scrollTop);
elseif(isMinNS4)
return(window.pageYOffset);
return(-1);
}
varg_p_zealNavigatorBar=null;
g_p_zealNavigatorBar=getLayer('zealNavigatorBar');
if(!isMinIE4){g_p_zealNavigatorBar.style.position='fixed';}
functionreposzealNavigatorBar(){
if(isMinIE4){
try{
moveLayerTo(g_p_zealNavigatorBar,
getPageLeft(g_p_zealNavigatorBar),
getPageScrollY());
}catch(e){}
}
}
window.onresize=reposzealNavigatorBar;
window.onscroll=reposzealNavigatorBar;
window.onload=reposzealNavigatorBar;
</script>
</BODY>
</HTML>