JavaScript Scalable Menu Simple Example

Source: Internet
Author: User

  Telescopic menu, we must have seen it, the implementation of the method is also many, in the next article for you to introduce the use of JS is how to achieve, the need for friends can refer to the following

The code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  <html>  <head>  <title> Scalable menu </title>  <style>  <!- -  body{  background-color: #ffdee0; }  #navigation {  width:200px; ;  }  #navigation > UL {  list-style-type:none;/* do not display bullets */  margin:0px;  padding:0px;  }  #navigation > Ul > Li {  border-bottom:1px solid #ED9F9F; * Add underscore */ }  #navigation > UL > li > a{  display:block;/* block display */  padding:5px 5px 5px 0.5em;  text-decoration:none;  border-l EFT:12PX Solid #711515/* The thick red edge on the left */  border-right:1px solid #711515;/* Right Shadow */ }  #navigation > Ul > Li > A:link, #navigation > Ul > li > a:visited{  background-color: #c11136;  color: #FFFFFF; }& nbsp #navigation > Ul > li > a:hover{/* mouse over */  background-color: #990020/* Change background color */  color: #ffff00; * Change text color */ }  &N Bsp  /* submenu CSS style */  #navigation ul li ul{  list-style-type:none;  margin:0px;  padding:0px 0px 0px 0px; }  #navigation ul Li ul li{  border-top:1px solid #ED9F9F; }  #navigation ul Li ul Li a{& nbsp display:block;  padding:3px 3px 3px 0.5em;  text-decoration:none;  border-left:28px solid #a71f1f;   BORDER-RIGHT:1PX solid #711515; }  #navigation ul Li ul Li A:link, #navigation ul Li ul Li A:visited{&nb Sp Background-color: #e85070;  color: #FFFFFF; }  #navigation ul Li ul Li a:hover{  background-color:# c2425d;  color: #ffff00; }  #navigation ul li ul.myhide{/* Hide submenu */  display:none; }  #nav Igation ul li ul.myshow{/* Display submenu */  display:block; } -->  </style>  <script Langu age= "JavaScript" >&NBsp function change () { //through the parent element Li, find the sibling element ul  var oseconddiv = this.parentNode.getElementsByTagName ("ul") [0];  //CSS alternating to realize explicit, hidden   if (Oseconddiv.classname = = "Myhide")   Oseconddiv.classname = "Myshow";  Else   Oseconddiv.classname = "Myhide"; }  window.onload = function () {  var Oul = document.getElementById ("Listul");  var aLi = oul.childnodes;//child element   var oa;  for (Var i=0;i<ali.length;i++) { //If the child element is Li , and this LI has submenu ul  if (ali[i].tagname = = "LI" && ali[i].getelementsbytagname ("ul"). Length) {  OA = Ali[i]. firstchild;//Find hyperlinks   Oa.onclick = change;//Dynamic Add click function  } } }  </script>  </head >  <body>  <div id= "navigation" >  <ul id= "Listul" >  <li><a href= "#" >Home</a></li>  <li><a href= "#" >News</a>  <ul class= "Myhide" >   <li><a href= "#" >lastest NEWS</A></LI≫  <li><a href= "#" >all news</a></li>  </ul>  </li>  <li ><a href= "#" >Sports</a>  <ul class= "myhide" >  <li><a href= "#" >basketball </a></li>  <li><a href= "#" >Football</a></li>  <li><a href= " # ">Volleyball</a></li>  </ul>  </li>  <li><a href=" # "> weather</a>  <ul class= "myhide" >  <li><a href= "#" >today ' s weather</a></ li>  <li><a href= "#" >Forecast</a></li>  </ul>  </li>  <li><a href= "#" >contact me</a></li>  </ul>  </div>  </body >  </html> 
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.