Many of my friends asked me about the code of the scroll navigation menu at the top of the Blog in various ways. In fact, there is nothing special, but since there is a need, I will sort out this part of the code for your reference.
Copy codeThe Code is as follows:
<! 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>
<TITLE> Float Div </TITLE>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Style type = "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: 1px solid #646465;
Background-color: # C0C0C3;
}
</Style>
</HEAD>
<BODY>
<Div id = zealNavigatorBar>
<A href = "/"> Anything here </a>
<A href = "/"> Anything here </a>
<A href = "/"> Anything here </a>
</Div>
<Script language = "JavaScript">
For (var t = 0; t <1000; t ++) document. writeln ('test content: line' + t + '<br/> ');
</Script>
<Script language = "JavaScript">
Var g_myBodyInstance = document. body;
Var g_myBodyInstanceString = "document. body ";
If (document. compatMode! = "BackCompat "){
// For looser. dtd
G_myBodyInstance = document.doc umentElement;
G_myBodyInstanceString = "document.doc umentElement ";
}
Var isMinNS4 = (navigator. appName. indexOf ("Netscape")> = 0 &&
ParseFloat (navigator. appVersion)> = 4 )? 1: 0;
Var isMinNS5 = (navigator. appName. indexOf ("Netscape")> = 0 &&
ParseFloat (navigator. appVersion)> = 5 )? 1: 0;
Var isMinIE4 = (document. all )? 1: 0;
Var isMinIE5 = (isMinIE4 & navigator. appVersion. indexOf ("5.")> = 0 )? 1: 0;
Var isMacIE = (isMinIE4 & navigator. userAgent. indexOf ("Mac")> = 0 )? 1: 0;
Var getFFVersion = navigator. userAgent. substring (
Navigator. userAgent. indexOf ("Firefox"). split ("/") [1];
// Extra height in px to add to iframe in FireFox 1.0 + browsers
Var FFextraHeight = getFFVersion <1.5? 16: 0;
Function getLayer (name ){
If (isMinNS5)
Return document. getElementById (name );
Else if (isMinIE4)
Return eval ('document. all. '+ name );
Else if (isMinNS4)
Return findLayer (name, document );
Return null;
}
Function findLayer (name, doc ){
Var I, layer;
For (I = 0; I <doc. layers. length; I ++ ){
Layer = doc. layers [I];
If (layer. name = name)
Return layer;
If (layer.doc ument. layers. length> 0 ){
Layer = findLayer (name, layer.doc ument );
If (layer! = Null)
Return layer;
}
}
Return null;
}
Function moveLayerTo (layer, x, y ){
If (isMinIE4 ){
Layer. style. left = x;
Layer. style. top = y;
}
Else if (isMinNS5 ){
Layer. style. left = x + 'px ';
Layer. style. top = y + 'px ';
}
Else if (isMinNS4)
Layer. moveTo (x, y );
}
Function getPageLeft (layer ){
If (isMinIE4 | isMinNS5)
Return (layer. offsetLeft );
Else if (isMinNS4)
Return (layer. pageX );
Return (-1 );
}
Function getPageTop (layer ){
If (isMinIE4 | isMinNS5)
Return (layer. offsetTop );
Else if (isMinNS4)
Return (layer. pageY );
Return (-1 );
}
Function getPageScrollX (){
If (isMinIE4 | isMinNS5)
Return (g_myBodyInstance.scrollLeft );
Else if (isMinNS4)
Return (window. pageXOffset );
Return (-1 );
}
Function getPageScrollY (){
If (isMinIE4 | isMinNS5)
Return (g_myBodyInstance.scrollTop );
Else if (isMinNS4)
Return (window. pageYOffset );
Return (-1 );
}
Var g_p_zealNavigatorBar = null;
G_p_zealNavigatorBar = getLayer ('zealnavigatorbar ');
If (! IsMinIE4) {g_p_zealNavigatorBar.style.position = 'fixed ';}
Function reposzealNavigatorBar (){
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>