Chinaunix首页 | 论坛 | 博客
  • 博客访问: 99010
  • 博文数量: 34
  • 博客积分: 925
  • 博客等级: 准尉
  • 技术积分: 350
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-15 11:52
文章分类

全部博文(34)

文章存档

2011年(34)

我的朋友

分类: 系统运维

2011-08-23 11:23:36


html代码:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
  2. <html>
  3.     <head>
  4.         <title>jQuery菜单</title>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.         <link type="text/css" rel="stylesheet" href="css/menu.css" />
  7.         <script type="text/javascript" src="js/jquery.js"> </script>
  8.         <script type="text/javascript" src="js/menu.js"> </script>
  9.     </head>
  10.     <body>

  11.         <ul class="lenovo-menu">
  12.             <li class="main">
  13.                     <a href="#">菜单项1</a>
  14.                 <ul>
  15.                     <li>
  16.                         <a href="#">子菜单项11</a>
  17.                     </li>
  18.                     <li>
  19.                         <a href="#">子菜单项12</a>
  20.                     </li>
  21.                 </ul>
  22.             </li>
  23.             <li class="main">
  24.                 <a href="#">菜单项2</a>
  25.                 <ul>
  26.                     <li>
  27.                         <a href="#">子菜单项21</a>
  28.                     </li>
  29.                     <li>
  30.                         <a href="#">子菜单项22</a>
  31.                     </li>
  32.                 </ul>
  33.             </li>
  34.             <li class="main">
  35.                 <a href="#">菜单项3</a>
  36.                 <ul>
  37.                     <li>
  38.                         <a href="#">子菜单项31</a>
  39.                     </li>
  40.                     <li>
  41.                         <a href="#">子菜单项32</a>
  42.                     </li>
  43.                 </ul>
  44.             </li>
  45.         </ul>
  46.         <br />
  47.         <br />
  48.         <br />

  49.         <ul>
  50.             <li class="hmain">
  51.                     <a href="#">菜单项1</a>
  52.                 <ul>
  53.                     <li>
  54.                         <a href="#">子菜单项11</a>
  55.                     </li>
  56.                     <li>
  57.                         <a href="#">子菜单项12</a>
  58.                     </li>
  59.                 </ul>
  60.             </li>
  61.             <li class="hmain">
  62.                 <a href="#">菜单项2</a>
  63.                 <ul>
  64.                     <li>
  65.                         <a href="#">子菜单项21</a>
  66.                     </li>
  67.                     <li>
  68.                         <a href="#">子菜单项22</a>
  69.                     </li>
  70.                 </ul>
  71.             </li>
  72.             <li class="hmain">
  73.                 <a href="#">菜单项3</a>
  74.                 <ul>
  75.                     <li>
  76.                         <a href="#">子菜单项31</a>
  77.                     </li>
  78.                     <li>
  79.                         <a href="#">子菜单项32</a>
  80.                     </li>
  81.                 </ul>
  82.             </li>
  83.         </ul>
  84.     
  85.     </body>
  86. </html>
menu.css
  1. ul, li {
  2.     /*清除ul和li上默认的小圆点*/
  3.     list-style: none;
  4. }
  5. ul {
  6.     /*清除子菜单的缩进值*/
  7.     padding: 0;
  8.     margin: 0;
  9. }
  10. .main, .hmain {
  11.     background-image: url(../images/title.gif);
  12.     background-repeat: repeat-x;
  13.     width: 120px;
  14. }
  15. li {
  16.     background-color: #EEEEEE;
  17. }
  18. a {
  19.     /*取消所有的下划线*/
  20.     text-decoration: none;
  21.     padding-left: 20px;
  22.     display: block;
  23.     display: inline-block;
  24.     width: 100px;
  25.     padding-top: 3px;
  26.     padding-bottom: 3px;
  27. }
  28. .main a, .hmain a {
  29.     color: white;
  30.     background-image: url(../images/collapsed.gif);
  31.     background-repeat: no-repeat;
  32.     background-position: 3px center;
  33. }
  34. .main li a, .hmain li a {
  35.     color: black;
  36.     background-image: none;
  37. }
  38. .main ul, .hmain ul {
  39.     display: none;
  40. }
  41. .hmain {
  42.     float: left;
  43.     margin-right: 1px;
  44. }
menu.js
  1. $(document).ready(function(){
  2.     //页面中的DOM已经装载完成时,执行的代码
  3.     $(".main > a").click(function(){
  4.         //找到主菜单项对应的子菜单项
  5.         var ulNode = $(this).next("ul");
  6.         /*
  7.         if (ulNode.css("display") == "none") {
  8.             ulNode.css("display","block");
  9.         } else {
  10.             ulNode.css("display","none");
  11.         }
  12.         */
  13.         //ulNode.show("slow");//normal fast
  14.         //ulNode.hide();
  15.         //ulNode.toggle();
  16.         //
  17.         //ulNode.slideDown("slow");
  18.         //ulNode.slideUp;
  19.         ulNode.slideToggle();
  20.         changeIcon($(this));
  21.     });
  22.     $(".hmain").hover(function(){
  23.         $(this).children("ul").slideDown();
  24.         changeIcon($(this).children("a"));
  25.     },function(){
  26.         $(this).children("ul").slideUp();
  27.         changeIcon($(this).children("a"));
  28.     });
  29. });

  30. /**
  31.  * 修改主菜单的指示图标
  32.  */
  33. function changeIcon(mainNode) {
  34.     if (mainNode) {
  35.         if (mainNode.css("background-image").indexOf("collapsed.gif") >= 0) {
  36.             mainNode.css("background-image","url('images/expanded.gif')");
  37.         } else {
  38.             mainNode.css("background-image","url('images/collapsed.gif')");
  39.         }
  40.     }
  41. }
阅读(370) | 评论(0) | 转发(0) |
0

上一篇:gvim 编辑器常用配置

下一篇:MyEclipse 设置

给主人留下些什么吧!~~