jquery实现垂直和水平菜单导航栏
本文实例为大家分享了jquery菜单导航栏的实现代码,供大家参考,具体内容如下
1. HTML代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>竖直导航菜单</title> <link href="css/Vmenu.css" rel="stylesheet" /> <script src="js/jquery-2.1.4.min.js"></script> <script> $(function(){ //垂直导航栏,点击下拉子菜单 $(".main>a").click(function(){ $(this).next().slideToggle(500) .parent().siblings().find(".child").slideUp(500); }) //水平导航栏,鼠标经过下拉导航栏 $(".hmain").hover(function(){ $(this).find(".child").slideToggle(500) .parent().siblings().find(".child").slideUp(); }) }) </script> </head> <body> <!--垂直导航栏--> <ul class="content"> <li class="main"><a href="#">菜单 1</a> <ul class="child"> <li>菜单1.1</li> <li>菜单1.2</li> <li>菜单1.3</li> </ul> </li> <li class="main"><a href="#">菜单 2</a> <ul class="child"> <li>菜单2.1</li> <li>菜单2.2</li> <li>菜单2.3</li> <li>菜单2.4</li> </ul> </li> <li class="main"><a href="#">菜单 3</a> <ul class="child"> <li>菜单3.1</li> <li>菜单3.2</li> <li>菜单3.3</li> </ul> </li> <li class="main"><a href="#">菜单 4</a> <ul class="child"> <li>菜单4.1</li> <li>菜单4.3</li> </ul> </li> <li class="main"><a href="#">菜单 5</a> <ul class="child"> <li>菜单5.1</li> <li>菜单5.2</li> </ul> </li> </ul> <!--水平导航栏--> <ul class="content"> <li class="hmain"><a href="#">菜单 1</a> <ul class="child"> <li>菜单1.1</li> <li>菜单1.2</li> <li>菜单1.3</li> </ul> </li> <li class="hmain"><a href="#">菜单 2</a> <ul class="child"> <li>菜单2.1</li> <li>菜单2.2</li> <li>菜单2.3</li> <li>菜单2.4</li> </ul> </li> <li class="hmain"><a href="#">菜单 3</a> <ul class="child"> <li>菜单3.1</li> <li>菜单3.2</li> <li>菜单3.3</li> </ul> </li> <li class="hmain"><a href="#">菜单 4</a> <ul class="child"> <li>菜单4.1</li> <li>菜单4.3</li> </ul> </li> <li class="hmain"><a href="#">菜单 5</a> <ul class="child"> <li>菜单5.1</li> <li>菜单5.2</li> </ul> </li> </ul> </body> </html>
2. CSS代码
*{ margin: 0px; padding: 0px; } .content{ margin: 40px 100px; float: left; } ul ,li{ list-style: none; } .main,.hmain{ width: 150px; background: #222; font-size: 16px; text-align: center; cursor: pointer; line-height: 40px; color: white; } .main>a,.hmain>a{ text-decoration: none; color: white; display: inline-block; width: 150px; min-height: 40px; } .main:hover,.hmain:hover{ background: black; } .child{ background: #444; display:none; } .child li:hover{ background: #333333; } /*垂直导航栏左浮动*/ .hmain{ float: left; }
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17