Heim > Web-Frontend > js-Tutorial > Hauptteil

关于Blog顶部的滚动导航条代码_javascript技巧

WBOY
Freigeben: 2016-05-16 19:26:01
Original
1163 Leute haben es durchsucht

不少朋友通过各种方式问我要 Blog 顶部的滚动导航菜单的代码。其实也没什么特别的,但既然有需求,我就还是把这部分代码整理出来,供大家参考。

复制代码 代码如下:

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Float Div






<script> <BR>for(var t=0;t<1000;t++) document.writeln('Test content: line '+t+'<br />'); <BR></script>
<script> <BR>var g_myBodyInstance = document.body; <BR>var g_myBodyInstanceString = "document.body"; <BR>if(document.compatMode != "BackCompat"){ <BR> // for looser.dtd <BR> g_myBodyInstance = document.documentElement; <BR> g_myBodyInstanceString = "document.documentElement"; <BR>} <BR>var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 && <BR> parseFloat(navigator.appVersion) >= 4) ? 1 : 0; <BR>var isMinNS5 = (navigator.appName.indexOf("Netscape") >= 0 && <BR> parseFloat(navigator.appVersion) >= 5) ? 1 : 0; <BR>var isMinIE4 = (document.all) ? 1 : 0; <BR>var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0; <BR>var isMacIE = (isMinIE4 && navigator.userAgent.indexOf("Mac") >= 0) ? 1 : 0; <br><br>var getFFVersion=navigator.userAgent.substring( <BR> navigator.userAgent.indexOf("Firefox")).split("/")[1]; <BR>//extra height in px to add to iframe in FireFox 1.0+ browsers <BR>var FFextraHeight=getFFVersion<1.5? 16 : 0; <br><br><BR>function getLayer(name) { <BR> if (isMinNS5) <BR> return document.getElementById(name); <BR> else if (isMinIE4) <BR> return eval('document.all.' + name); <BR> else if (isMinNS4) <BR> return findLayer(name, document); <br><br> return null; <BR>} <br><br>function findLayer(name, doc) { <br><br> var i, layer; <br><br> for (i = 0; i < doc.layers.length; i++) { <BR> layer = doc.layers[i]; <BR> if (layer.name == name) <BR> return layer; <BR> if (layer.document.layers.length > 0) { <BR> layer = findLayer(name, layer.document); <BR> if (layer != null) <BR> return layer; <BR> } <BR> } <br><br> return null; <BR>} <br><br>function moveLayerTo(layer, x, y) { <BR> if (isMinIE4) { <BR> layer.style.left = x; <BR> layer.style.top = y; <BR> } <BR> else if (isMinNS5) { <BR> layer.style.left = x+'px'; <BR> layer.style.top = y+'px'; <BR> } <BR> else if (isMinNS4) <BR> layer.moveTo(x, y); <BR>} <br><br>function getPageLeft(layer) { <br><br> if (isMinIE4||isMinNS5) <BR> return(layer.offsetLeft); <BR> else if (isMinNS4) <BR> return(layer.pageX); <BR> return(-1); <BR>} <br><br>function getPageTop(layer) { <br><br> if (isMinIE4||isMinNS5) <BR> return(layer.offsetTop); <BR> else if (isMinNS4) <BR> return(layer.pageY); <BR> return(-1); <BR>} <br><br>function getPageScrollX() { <br><br> if (isMinIE4||isMinNS5) <BR> return(g_myBodyInstance.scrollLeft); <BR> else if (isMinNS4) <BR> return(window.pageXOffset); <BR> return(-1); <BR>} <br><br>function getPageScrollY() { <br><br> if (isMinIE4||isMinNS5) <BR> return(g_myBodyInstance.scrollTop); <BR> else if (isMinNS4) <BR> return(window.pageYOffset); <BR> return(-1); <BR>} <br><br>var g_p_zealNavigatorBar = null; <BR>g_p_zealNavigatorBar = getLayer('zealNavigatorBar'); <BR>if(!isMinIE4){g_p_zealNavigatorBar.style.position = 'fixed';} <BR>function reposzealNavigatorBar(){ <BR> if(isMinIE4){ <BR> try{ <BR> moveLayerTo(g_p_zealNavigatorBar, <BR> getPageLeft(g_p_zealNavigatorBar), <BR> getPageScrollY()); <BR> }catch(e){} <BR> } <BR>} <BR>window.onresize = reposzealNavigatorBar; <BR>window.onscroll = reposzealNavigatorBar; <BR>window.onload = reposzealNavigatorBar; <BR></script>


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage