當(dāng)前位置:軟件學(xué)堂 > 資訊首頁(yè) > 網(wǎng)絡(luò)編程 > 編程其他 > JS代碼實(shí)現(xiàn)靜態(tài)導(dǎo)航菜單效果

JS代碼實(shí)現(xiàn)靜態(tài)導(dǎo)航菜單效果

2012/11/2 16:06:26作者:佚名來源:網(wǎng)絡(luò)

移動(dòng)端

【實(shí)例名稱】

JS代碼實(shí)現(xiàn)靜態(tài)導(dǎo)航菜單效果

【實(shí)例描述】

靜態(tài)導(dǎo)航菜單一般用于內(nèi)容比較固定的網(wǎng)站,大多都是小型網(wǎng)站。菜單的內(nèi)容都是預(yù)先設(shè)置好的,不允許在運(yùn)行時(shí)動(dòng)態(tài)改變。

【實(shí)例代碼】

 

<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>標(biāo)題頁(yè)-學(xué)無憂(www.wangbatian.cn)</title> </head> <BODY bgcolor="#ffffff" OnLoad="setVariables();checkLocation()">

<script language="JavaScript">

function setVariables() { if (navigator.appName == "Netscape") { //瀏覽器是netscape的情況     v=".top=";     dS="document.";     sD="";     y="window.pageYOffset";     } else {                                  //瀏覽器是ie的情況     v=".pixelTop=";     dS="";     sD=".style";     y="document.body.scrollTop";       //如果頁(yè)面有滾動(dòng)條,獲取滾動(dòng)條的頂端位置    } } function checkLocation() {     object="object1";                   //獲取指定的div     yy=eval(y);     eval(dS+object+sD+v+yy);            //連接字符串,旨在讓靜態(tài)導(dǎo)航菜單一直在頁(yè)面滾動(dòng)條的上端     setTimeout("checkLocation()",10); } </script> <div id="object1"  style="position:absolute; visibility:show; left:0px; top:0px; z-index:5">   <table width=150 border=0 cellspacing=20 cellpadding=0 >     <tr>       <td bgcolor="#EAEAEA">         <center>           靜態(tài)導(dǎo)航菜單         </center>       </td>     </tr>     <tr>       <td bgcolor="#EAEAEA"><a href="http://www.microsoft.com" >微軟網(wǎng)站</a></td>     </tr>     <tr>       <td bgcolor="#EAEAEA"><a href="http://www.yahoo.com" >雅虎網(wǎng)站</a></td>     </tr>     <tr>       <td bgcolor="#EAEAEA"><a href="http://www.baidu.com">百度搜索</a></td>     </tr>     <tr>       <td bgcolor="#EAEAEA"><a href="http://mail.263.com" >263郵局</a></td>     </tr>   </table>   </div> </body> </html>

 

【運(yùn)行效果】

 靜態(tài)導(dǎo)航菜單運(yùn)行效果

【難點(diǎn)剖析】

本例中頁(yè)面的布局很重要,使用一個(gè)table封裝所有的靜態(tài)鏈接,然后將table放在div層中。使用“checkLocation”方法設(shè)置層的位置一直顯示在滾動(dòng)條的頂端位置。

【源碼下載】

為了JS代碼的準(zhǔn)確性,請(qǐng)點(diǎn)擊:靜態(tài)導(dǎo)航菜單 進(jìn)行本實(shí)例源碼下載