Home >Web Front-end >JS Tutorial >JavaScript realizes the effect of multi-level web page menu extending to the right_javascript skills
The example in this article describes the JavaScript implementation of a multi-level web page menu effect extending to the right. Share it with everyone for your reference. The details are as follows:
JavaScript is used here to achieve the effect of a multi-level web menu extending to the right. When the mouse is placed on the main menu on the left, a secondary menu stretches out on the right. It is basically not beautified. It is written by a novice. Corrections are welcome and need to be improved. There are quite a few places.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-right-show-web-menu-codes/
The specific code is as follows:
<!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>艺术</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>
I hope this article will be helpful to everyone’s JavaScript programming design.