Simple example of JavaScript telescopic menu_javascript skills
May 16, 2016 pm 05:10 PM
javascript
Telescopic menu
Copy code 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>Telescopic menu</title>
<style>
<!--
body{
background-color:#ffdee0;
}
#navigation {
width:200px;
font-family:Arial;
}
#navigation > ul {
list-style-type:none;/* Do not display bullet points*/
margin:0px;
padding:0px;
}
#navigation > ul > li {
border-bottom:1px solid #ED9F9F;/* Add underline*/
}
#navigation > ul > li > a{
display:block;/* block display*/
padding:5px 5px 5px 0.5em;
text-decoration:none;
border-left:12px solid #711515;/* thick red edge on the left*/
border-right:1px solid #711515;/* shadow on the right*/
}
#navigation > ul > li > a:link, #navigation > ul > li > a:visited{
background-color:#c11136;
color:#FFFFFF;
}
# navigation > ul > li > a:hover{ /* When the mouse passes over */
background-color:#990020;/* Change the background color*/
color:#ffff00;/* Change the text color */
}
/* CSS style of submenu*/
#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{
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{
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;
}
#navigation ul li ul.myShow{ /* Show submenu*/
display:block;
}
-- >
</style>
<script language="javascript">
function change(){
//Through the parent element li, find the sibling element ul
var oSecondDiv = this.parentNode.getElementsByTagName("ul")[0];
//CSS is alternately replaced to realize display and concealment
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 hyperlink
oA.onclick = change;//Dynamicly 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>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement an online speech recognition system using WebSocket and JavaScript

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript

How to use JavaScript and WebSocket to implement a real-time online ordering system

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Simple JavaScript Tutorial: How to Get HTTP Status Code

How to get HTTP status code in JavaScript the easy way

How to use insertBefore in javascript
