Home > Web Front-end > JS Tutorial > body text

jQuery code to implement three-level menu_jquery

WBOY
Release: 2016-05-16 09:00:28
Original
1763 people have browsed it

last week i took over a new website construction job, which required jquery code to implement a three-level menu. in fact, it is not difficult at all. the editor will share the code with you for your reference.

let me show you the renderings first. if you feel good about it, please refer to the implementation code.

html code:

<body> 
<div class="navmenu"> 
<ul> 
<li><a href="#">首页</a> 
<ul> 
<li><a href="#">javascript+</a> 
<ul> 
<li><a href="#">三角函数</a></li> 
<li><a href="#">矩形</a></li> 
</ul> 
</li> 
<li><a href="#">语文</a> 
<ul> 
<li><a href="#">唐诗</a></li> 
<li><a href="#">宋词</a></li> 
</ul> 
</li> 
<li><a href="#">英语</a></li> 
</ul> 
</li> 
<li><a href="#">课程大厅</a></li> 
<li><a href="#">学习中心+</a> 
<ul> 
<li><a href="#">javascript+</a> 
<ul> 
<li><a href="#">三角函数</a></li> 
<li><a href="#">矩形</a></li> 
</ul> 
</li> 
<li><a href="#">语文</a> 
<ul> 
<li><a href="#">三角函数</a></li> 
<li><a href="#">矩形</a></li> 
</ul> 
</li> 
<li><a href="#">英语</a></li> 
</ul> 
</li> 
<li><a href="#">帮助</a></li> 
</ul> 
</div> 
</body> 
Copy after login

js code:

<script type="text/javascript" src="js/jquery-1.12.3.min.js"></script> 
<script type="text/javascript"> 
$(function(){ 
$("li").has("ul").mouseover(function(){ 
$(this).children("ul").css("display","block"); 
$(this).css("backgroundcolor","#0066ff"); 
}).mouseout(function () { 
$(this).children("ul").css("display","none"); 
$(this).css("backgroundcolor","#eee"); 
}) 
}) 
</script> 
Copy after login

css code:

*{ 
padding:0; 
margin:0; 
} 
/*一级菜单*/ 
.navMenu { 
width:570px; 
margin:0 auto; 
} 
.navMenu ul li{ 
float: left; 
position: relative; 
} 
li{ 
list-style: none; 
background-color: #eee; 
width: 140px; 
height: 40px; 
text-align: center; 
margin-right: 2px; 
margin-bottom: 2px; 
} 
ul li a{ 
line-height: 40px; 
text-align: center; 
font-size: 20px; 
color: #000; 
text-decoration: none; 
display: block; 
padding:0 10px; 
} 
/*二级菜单*/ 
.navMenu ul li ul { 
display: none; 
position:absolute; 
left: 0; 
top:0; 
margin-top:42px; 
} 
.navMenu ul li ul li{ 
float:none; 
} 
/*三级菜单*/ 
.navMenu ul li ul li ul{ 
display: none; 
left:140px; 
top:-42px; 
} 
Copy after login

the above content is the jquery code to implement a three-level menu introduced by the editor. i hope it will be helpful to you!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template