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

JS代碼實(shí)現(xiàn)仿Flash菜單效果

2012/11/2 16:14:43作者:佚名來(lái)源:網(wǎng)絡(luò)

移動(dòng)端

【實(shí)例名稱】

仿Flash菜單

【實(shí)例描述】

用JavaScript可以很輕松地構(gòu)建菜單。本例學(xué)習(xí)制作一個(gè)具有Flash效果的菜單。

【實(shí)例代碼】

<html xmlns="http://www.w3.org/1999/xhtml" > <head>     <title>無(wú)標(biāo)題頁(yè)-學(xué)無(wú)憂(www.yzddtk.cn)</title> <script language=javascript> // 綁定菜單的事件 function attachXMenu(objid) {  var tds=objid.getElementsByTagName('td');  for(var i=0;i<tds.length;i++){   with(tds[i]){    onmouseover=function(){     with(this){      filters[0].apply();      style.background='#66CCFF';        //鼠標(biāo)移上去時(shí)的背景顏色      style.border='1px solid #ffffff';  //邊框      style.color='black';               //文字顏色      filters[0].play();     }    }    onmouseout=function(){     with(this){      filters[0].apply();      style.background='#336699';       //這是鼠標(biāo)離開(kāi)時(shí)的背景顏色      style.border='1px solid #336699'; //邊框      style.color='#ffffff';            //文字顏色      filters[0].play();     }    }   }  } } </script>

需要添加菜單的樣式表,代碼如下所示:

<style> .xmenu td{font-size:12px;font-family: verdana,arial;font-weight:bolder;color:#ffffff; border:1px solid #336699;background:#336699; filter:blendtrans(duration=0.5); cursor:hand;text-align:center;} </style>

需要在body中添加一個(gè)表格,用來(lái)制作菜單,代碼如下所示: </head> <body>  <table class="xmenu" id="xmenu1" width="100" cellpadding="1" cellspacing="4" border="0" bgcolor="#336699" align="center">  <tr><td>Name</td></tr>  <tr><td>Age</td></tr>  <tr><td>Address</td></tr>  <tr><td>City</td></tr>  <tr><td>Grade</td></tr>  <tr><td>Teacher</td></tr> </table> <script>attachXMenu(xmenu1);</script> </body> </html>

【運(yùn)行效果】

 仿Flash菜單運(yùn)行效果

【難點(diǎn)剖析】

本例中有樣式變換和動(dòng)態(tài)事件兩個(gè)重點(diǎn)。為了突出flash效果.當(dāng)鼠標(biāo)移動(dòng)到菜單上時(shí),菜單的樣式需要發(fā)生變化,這歸功于樣式表和“attachxMenu”  方法。  在  “attachXMenu” 中,  使用“onmouseover=function()”語(yǔ)句為菜單添加了動(dòng)態(tài)事件。

【源碼下載】

為了JS代碼的準(zhǔn)確性,請(qǐng)點(diǎn)擊:仿Flash菜單 進(jìn)行本實(shí)例源碼下載 

標(biāo)簽: JS代碼  Flash菜單