A super simple drop down menu with jquery
- 2020-03-30 02:59:24
- OfStack
A super simple drop-down menu with jquery.
rendering
Effect of initial
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140518162341.gif? 2014418162423 ">
Hover effect
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140518162448.gif? 201441816250 ">
code
rendering
Effect of initial
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140518162341.gif? 2014418162423 ">
Hover effect
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140518162448.gif? 201441816250 ">
code
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<style>
nav a {
text-decoration: none;
}
nav > ul > li {
float: left;
text-align: center;
padding: 0 0.5em;
}
nav li ul.sub-menu {
display: none;
padding-left: 0 !important;
}
.sub-menu li {
color: white;
}
.sub-menu li:hover {
background-color: black;
}
.sub-menu li:hover a {
color: white;
}
ul {
list-style: none;
}
</style>
</head>
<body>
<nav>
<ul>
<li><a href="#">Home
<ul class="sub-menu">
<li><a href="#">sub1</a></li>
<li><a href="#">sub2</a></li>
<li><a href="#">sub3</a></li>
</ul>
</li>
<li><a href="#">Programming
<ul class="sub-menu">
<li><a href="#">sub1</a></li>
<li><a href="#">sub2</a></li>
<li><a href="#">sub3</a></li>
</ul>
</li>
<li><a href="#">Japanese
<ul class="sub-menu">
<li><a href="#">sub1</a></li>
<li><a href="#">sub2</a></li>
<li><a href="#">sub3</a></li>
</ul>
</li>
</ul>
</nav>
</body>
<script type="text/javascript">
$(document).ready(function() {
$('nav li').hover(function() {
$(this).find('.sub-menu').css('display', 'block');
}, function() {
$(this).find('.sub-menu').css('display', 'none');
});
});
</script>
</html>