本文實例講述了js實現帶圓角的兩級導航菜單效果代碼。分享給大家供大家參考。具體如下:
這是一款使用JS做的圓角菜單,支持兩級菜單顯示,本人比較喜歡的風格,修改使用方便,新手也能上手快。使用有幾張圓角圖片來修飾了菜單,喜歡的朋友可以下載代碼留作收藏使用。真心不錯的藍色導航條代碼。
運行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/js-cicle-nav-menu-style-codes/
具體代碼如下:
<!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>圓角藍色橫向二級菜單代碼,鼠標經過顯示子菜單</title> <script> function MM_reloadPage(init) { if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_showHideLayers() { //v6.0 var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; } obj.visibility=v; } } </script> <style type="text/css"> body {font-family:\5B8B\4F53,Arial Narrow,arial,serif;background:#ffffff;font-size:12px;} body,div,dl,dt,dd,ul,ol,li,pre,form,fieldset,input,textarea,blockquote,emBED{padding:0; margin:0;} li{list-style-type:none;} a{text-decoration:none;color:#20537A;} a:hover{text-decoration:underline;} .topmenu{width:980px;height:42px; margin:0 auto;position: relative;left:0px; top:0px;background:url('images/nav_li_bg.gif') repeat-x right center;} .topmenu .nav_content{padding-left:25px;background:url('images/nav_li_left.gif') no-repeat;float:left;} .topmenu .nav_content li{width:126px;height:42px;float:left;line-height:42px;background:url('images/nav_li_line.gif') no-repeat right;text-align:center;font-weight:bold;} .topmenu .nav_content li a{color:#fff;width:126px;height:42px;display:block;} .topmenu .nav_content li.current a{width:126px;height:42px;line-height:42px;display:block;color:#fff;} .topmenu .nav_content li.current a:hover{line-height:42px;} .topmenu .nav_content li a:hover{line-height:42px;text-decoration:none;background:url('images/nav_li_hover.gif') no-repeat;color:#000;} .topmenu .nav_content li.end{background: none;} .topmenu .nav_content li.right{padding-left:47px;width:26px;background:url('images/nav_li_right.gif') no-repeat right top;height:42px;} .submenu{visibility: hidden;position:absolute;top:42px;left:0;background:url('images/sub_li_bg.gif') repeat-x right top;} .submenu .subnav{padding-left:33px;background:url('images/sub_li_left.gif') no-repeat;float:left;} .submenu .subnav li{height40px;float:left;background:url('images/arrow.gif') no-repeat left 15px;} .submenu .subnav li a{color:#333;display:block;padding:0 12px;line-height:40px; text-decoration:none;} .submenu .subnav li a:hover{color:#0a4aaa;text-decoration:none;} .submenu .subnav li.subright{width:33px;background:url('images/sub_li_right.gif') no-repeat right top;height:40px;} #Layer1{left:30px;} #Layer2{left:80px;} #Layer3{left:280px;} #Layer4{left:400px;} #Layer5{left:auto;right:80px;} </style> </head> <body> <div style="height:70px;"></div> <div class="topmenu"> <div class="nav_content"> <ul> <li><a href="#">首 頁</a></li> <li><a href="#" onMouseOver="MM_showHideLayers('Layer1','','show')" onMouseOut="MM_showHideLayers('Layer1','','hide')">網頁特效</a></li> <li><a href="#" onMouseOver="MM_showHideLayers('Layer2','','show')" onMouseOut="MM_showHideLayers('Layer2','','hide')">電子商務</a></li> <li><a href="#" onMouseOver="MM_showHideLayers('Layer3','','show')" onMouseOut="MM_showHideLayers('Layer3','','hide')">導航條</a></li> <li><a href="#" onMouseOver="MM_showHideLayers('Layer4','','show')" onMouseOut="MM_showHideLayers('Layer4','','hide')">網絡廣告</a></li> <li><a href="#" onMouseOver="MM_showHideLayers('Layer5','','show')" onMouseOut="MM_showHideLayers('Layer5','','hide')">搜索引擎</a></li> <li><a href="#" >關於我們</a></li> <li class="right"></li> </ul> </div> <div id="Layer1" class="submenu" onMouseOver="MM_showHideLayers('Layer1','','show')" onMouseOut="MM_showHideLayers('Layer1','','hide')"> <div class="subnav"> <ul> <li><a href="">源碼下載</a></li> <li><a href="">導航條代碼</a></li> <li><a href="">電子商務</a></li> <li><a href="">營銷外包</a></li> <li><a href="">電子商務</a></li> <li class="subright"></li> </ul> </div> </div> <div id="Layer2" class="submenu" onMouseOver="MM_showHideLayers('Layer2','','show')" onMouseOut="MM_showHideLayers('Layer2','','hide')"> <div class="subnav"> <ul> <li><a href="">編程書籍</a></li> <li><a href="">導航條代碼</a></li> <li><a href="">商務人才</a></li> <li><a href="">網絡外包</a></li> <li><a href="">電子商務</a></li> <li><a href="">導航條代碼</a></li> <li class="subright"></li> </ul> </div> </div> <div id="Layer3" class="submenu" onMouseOver="MM_showHideLayers('Layer3','','show')" onMouseOut="MM_showHideLayers('Layer3','','hide')"> <div class="subnav"> <ul> <li><a href="">論壇社區</a></li> <li><a href="">導航條代碼</a></li> <li><a href="">電子商務人才</a></li> <li><a href="">電子商務</a></li> <li class="subright"></li> </ul> </div> </div> <div id="Layer4" class="submenu" onMouseOver="MM_showHideLayers('Layer4','','show')" onMouseOut="MM_showHideLayers('Layer4','','hide')"> <div class="subnav"> <ul> <li><a href="">教程文章</a></li> <li><a href="">導航條代碼</a></li> <li><a href="">網站分類</a></li> <li><a href="">電子商務</a></li> <li class="subright"></li> </ul> </div> </div> <div id="Layer5" class="submenu" onMouseOver="MM_showHideLayers('Layer5','','show')" onMouseOut="MM_showHideLayers('Layer5','','hide')"> <div class="subnav"> <ul> <li><a href="">最新更新</a></li> <li><a href="">導航條代碼</a></li> <li><a href="">分類信息網</a></li> <li><a href="">電子商務</a></li> <li class="subright"></li> </ul> </div> </div> </div> </body> </html>
希望本文所述對大家的javascript程序設計有所幫助。