jQuery 菜单

简介:

一、垂直菜单的实现 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
< html >
     < head >
         < meta  charset = "UTF-8" >
         < title ></ title >
         < link  href = "app.css"  rel = "stylesheet" />
         < script  src = "jquery-1.10.1.min.js" ></ script >
         < script  src = "app.js" ></ script >
     </ head >
     < body >
         < ul >
             < li  class = "main" >
                 < a  href = "#" >菜单1</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
             < li  class = "main" >
                 < a  href = "#" >菜单2</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
             < li  class = "main" >
                 < a  href = "#" >菜单3</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
         </ ul >
     </ body >
</ html >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ul,li{
     list-style none ;
}
 
ul{
     padding 0 ;
     margin 0 ;
}
 
.main{
     background-color #666666 ;
     background-repeat repeat-x ;
     width 100px ;
}
 
li{
     background-color #eeeeee ;
}
 
a{
     text-decoration none ;
     padding-left 20px ;
     display block ;
     width 80px ;
     padding-top 3px ;
     padding-bottom 3px ;
}
 
.main a{
     color white ;
}
 
.main li a{
     color black ;
}
 
.main ul{
     display none ;
}
1
2
3
4
5
6
$(document).ready( function (){
     $( ".main>a" ).click( function (){
         var  ulNode = $( this ).next( "ul" );
         ulNode.toggle( "normal" );
     });
});


二、水平菜单的实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
< html >
     < head >
         < meta  charset = "UTF-8" >
         < title ></ title >
         < link  href = "app.css"  rel = "stylesheet" />
         < script  src = "jquery-1.10.1.min.js" ></ script >
         < script  src = "app.js" ></ script >
     </ head >
     < body >
         < ul >
             < li  class = "main" >
                 < a  href = "#" >菜单1</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
             < li  class = "main" >
                 < a  href = "#" >菜单2</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
             < li  class = "main" >
                 < a  href = "#" >菜单3</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
         </ ul >
         < br  />
         < br  />
         < br  />
         < br  />
         < br  />
         < ul >
             < li  class = "hmain" >
                 < a  href = "#" >菜单1</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
             < li  class = "hmain" >
                 < a  href = "#" >菜单2</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
             < li  class = "hmain" >
                 < a  href = "#" >菜单3</ a >
                 < ul >
                     < li >< a  href = "#" >子菜单1</ a ></ li >
                     < li >< a  href = "#" >子菜单2</ a ></ li >
                 </ ul >
             </ li >
         </ ul >
     </ body >
</ html >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
ul,li{
     list-style none ;
}
 
ul{
     padding 0 ;
     margin 0 ;
}
 
.main,.hmain{
     background-color #666666 ;
     background-repeat repeat-x ;
     width 100px ;
}
 
li{
     background-color #eeeeee ;
}
 
a{
     text-decoration none ;
     padding-left 20px ;
     display block ;
     width 80px ;
     padding-top 3px ;
     padding-bottom 3px ;
}
 
.main a,.hmain a{
     color white ;
}
 
.main li a,.hmain li a{
     color black ;
}
 
.main ul,.hmain ul{
     display none ;
}
 
.hmain{
     float left ;
     margin-right 1px ;
}
 
.main{
     margin-top 1px ;
}
1
2
3
4
5
6
7
8
9
10
11
12
$(document).ready( function (){
     $( ".main>a" ).click( function (){
         var  ulNode = $( this ).next( "ul" );
         ulNode.toggle( "normal" );
     });
     
     $( ".hmain" ).hover( function (){
         $( this ).children( "ul" ).slideDown();
     }, function (){
         $( this ).children( "ul" ).slideUp();
     });
});

   


本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1795236






相关文章
|
2月前
|
JavaScript
jQuery 树型菜单插件(Treeview)
jQuery 树型菜单插件(Treeview)
67 2
|
4天前
|
JavaScript 前端开发
jQuery和CSS3滑动展开菜单按钮插件
这是一款jQuery和CSS3滑动展开菜单按钮插件。该滑动展开菜单按钮在用户点击主菜单按钮之后,子菜单以滑动的方式依次展开
39 21
|
7月前
|
JSON JavaScript 数据格式
jQuery 树型菜单完整代码
jQuery 树型菜单完整代码
|
7月前
|
JavaScript
jQuery实现二级菜单
jQuery实现二级菜单
|
JavaScript
jQuery水平滑动菜单
在线演示 本地下载
990 0
|
JavaScript
jQuery多层级垂直手风琴菜单
在线演示 本地下载
1115 0
|
JavaScript
|
JavaScript 前端开发
|
JavaScript
jQuery扁平化风格手风琴菜单
在线演示 本地下载
873 0
|
Web App开发 JavaScript
JQuery实现层级菜单
效果图: HTML代码如下:   层级菜单 body{ font-family:'Microsoft Yahei'; } body,ul{ margin:0px; padding:0px; } ul{list-style:none;} .
1135 0