当前位置:软件学堂 > 资讯首页 > 网络编程 > 编程其他 > JS代码实现仿Flash菜单效果

JS代码实现仿Flash菜单效果

2012/11/2 16:14:43作者:佚名来源:网络

移动端

【实例名称】

仿Flash菜单

【实例描述】

用JavaScript可以很轻松地构建菜单。本例学习制作一个具有Flash效果的菜单。

【实例代码】

<html xmlns="http://www.w3.org/1999/xhtml" > <head>     <title>无标题页-学无忧(www.xue51.com)</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';        //鼠标移上去时的背景颜色      style.border='1px solid #ffffff';  //边框      style.color='black';               //文字颜色      filters[0].play();     }    }    onmouseout=function(){     with(this){      filters[0].apply();      style.background='#336699';       //这是鼠标离开时的背景颜色      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中添加一个表格,用来制作菜单,代码如下所示: </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>

【运行效果】

 仿Flash菜单运行效果

【难点剖析】

本例中有样式变换和动态事件两个重点。为了突出flash效果.当鼠标移动到菜单上时,菜单的样式需要发生变化,这归功于样式表和“attachxMenu”  方法。  在  “attachXMenu” 中,  使用“onmouseover=function()”语句为菜单添加了动态事件。

【源码下载】

为了JS代码的准确性,请点击:仿Flash菜单 进行本实例源码下载 

标签: 菜单