JavaScript實現(xiàn)向右伸出的多級網(wǎng)頁菜單效果
本文實例講述了JavaScript實現(xiàn)向右伸出的多級網(wǎng)頁菜單效果。分享給大家供大家參考。具體如下:
這里使用JavaScript實現(xiàn)向右伸出的多級網(wǎng)頁菜單效果,鼠標放在左側(cè)的主菜單上,右側(cè)就伸展出二級菜單,基本沒有美化,新手所寫,歡迎指正,需要完善的地方還挺多。
運行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/js-right-show-web-menu-codes/
具體代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>向右伸出的多級菜單</title> <style type="text/css"> *{ padding:0; margin:0; } li{ list-style:none; } ul{ background:rgb(200,13,34); width:250px; float:left; } b{ display:block; width:500px; height:40px; background:rgb(24,122,173); } ul li{ height:32px; } ul li:hover{ height:32px; background:orange; } #nav1{ position:absolute; } #nav3{ position:relative; left:0; background:green; visibility:hidden; } </style> </head> <body> <div id="nav1"> <ul id="nav2"> <li>文學</li> <li>藝術(shù)</li> <li>攝影</li> </ul> <ul id="nav3"> <li>1-1</li> <li>2-1</li> <li>3-1</li> </ul> </div> <script type="text/javascript"> var focus=false; var showdiv=document.getElementById("nav3"); showdiv.onmouseover=function(){ focus=true; this.style.visibility="visible"; } showdiv.onmouseout=function(){ focus=false; this.style.visibility="hidden"; } function bindToggle(index,flag){ var showdiv= document.getElementById("nav3"); var delayshow= function(){ if(flag ==1 ){ showdiv.style.visibility="visible"; showdiv.style.top=index*32+"px"; }else { if(!focus){ showdiv.style.visibility="hidden"; } } } return function(){ setTimeout(delayshow,150); } } var menu=document.getElementById("nav2").childNodes; var index=0; for(var i=0;i<menu.length;i++){ if(1==menu[i].nodeType){ menu[i].onmouseover= bindToggle.call(menu[i],index,1); menu[i].onmouseout= bindToggle.call(menu[i],index,0); index++; } } </script> </body> </html>
希望本文所述對大家的javascript程序設計有所幫助。
相關(guān)文章
擴展javascript的Date方法實現(xiàn)代碼(prototype)
長期從事C#的開發(fā),被C#影響著我的思維。C#中DateTime的操作就很方便,于是就參考它對js的Date做了擴展。2010-11-11javascript+HTML5 Canvas繪制轉(zhuǎn)盤抽獎
這篇文章主要為大家詳細介紹了javascrip+HTML5 Canvas繪制轉(zhuǎn)盤抽獎的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-04-04WebGL three.js學習筆記之陰影與實現(xiàn)物體的動畫效果
這篇文章主要介紹了WebGL three.js學習筆記 陰影與實現(xiàn)物體的動畫 ,需要的朋友可以參考下2019-04-04