We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

vbert on 02/13/08


Tagged

css javascript menu xhtml jquery


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

adix
vbert
machinehuman
martingoldszein
joomla


Slide menu


Published in: JavaScript 


URL: http://jquery.com/

/**
* Slide menu with jQuery
*
* @package bitemibajtem.pl
* @copyright 2007-2008 (C) BITEM I BAJTEM
* @author Wojciech Sobczak (vbert)
* @access public
*/


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
  3. <head>
  4. <title>Slide menu with jQuery</title>
  5. <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  6. <meta http-equiv="Content-Language" content="pl" />
  7. <meta http-equiv="Pragma" content="no-cache" />
  8. <meta name="Author" content="Wojciech Sobczak (vbert)" />
  9. <style rel="stylesheet" type="text/css" media="screen">
  10. html, body { margin: 0; padding: 0; border: 0 none; height: 100%; }
  11. div, span, ul, ol, dl, dt, dd { margin: 0; padding: 0; border: 0; }
  12. ul, ol, dl, dt, dd { list-style: none; }
  13. a, a:visited, a:hover { text-decoration: none; }
  14. a { color: #dcdc05; outline: none !important; }
  15. a:hover { color: #00c900; }
  16. legend { display: none; }
  17. body { background: #2e3436; color: #d3d6cf; font-size: 13px; }
  18. #container { margin: 100px auto; padding: 2px; width: 300px; border: 1px solid #666; text-align: center; }
  19. #menu { width: 300px; margin: 0 auto; text-align: left; }
  20. dt { margin-top: 2px; height: 34px; }
  21. dt a {
  22. display: block;
  23. height: 34px;
  24. padding-left: .35em;
  25. line-height: 34px;
  26. background: #222;
  27. font-family: Georgia, "Bookman Old Style", "Bookman Antiqua",serif;
  28. font-size: 1.5em;
  29. font-weight: bold;
  30. }
  31. dt.first { margin-top: 0; }
  32. #item-1 a, #sitem-1 a { color: #f9dc3f; }
  33. #item-2 a, #sitem-2 a { color: #8ff501; }
  34. #item-3 a, #sitem-3 a { color: #00c089; }
  35. #item-4 a, #sitem-4 a { color: #028eda; }
  36. #item-1 a:hover, #item-1 a.selected:hover,
  37. #sitem-1 a:hover, #sitem-1 a.selected:hover,
  38. #item-2 a:hover, #item-2 a.selected:hover,
  39. #sitem-1 a:hover, #sitem-1 a.selected:hover,
  40. #item-3 a:hover, #item-3 a.selected:hover,
  41. #sitem-3 a:hover, #sitem-3 a.selected:hover,
  42. #item-4 a:hover, #item-4 a.selected:hover,
  43. #sitem-4 a:hover, #sitem-4 a.selected:hover {
  44. color: #fff;
  45. }
  46. dt a:hover, dt a.selected:hover,
  47. dd a:hover, dd a.selected:hover {
  48. cursor: pointer;
  49. background: #3b98e2;
  50. }
  51. dd { margin-bottom: 2px; border-bottom: 1px solid #666; }
  52. dd.last { border-bottom: 0 none; }
  53. dd ul li { height: 24px; }
  54. dd ul li a {
  55. display: block;
  56. padding-left: 20px;
  57. height: 24px;
  58. line-height: 24px;
  59. background: transparent;
  60. font-family: "Lucida Grande", LucidaGrande, Geneva, Verdana, sans-serif;
  61. font-size: 1.1em;
  62. font-weight: bold;
  63. }
  64. </style>
  65.  
  66. <script type="text/javascript" src="http://vbert.gildia.info/_proj/lib/jquery.pack.js"></script>
  67.  
  68. <script type="text/javascript">
  69. $(document).ready(function(){
  70. if($("#menu")) {
  71. $("#menu dd").hide(); //:not(:first)
  72. $("#menu dt a").click(function() {
  73. if($(this).hasClass("selected")) {
  74. $(this).parent().next().slideUp(200);
  75. $(this).removeClass();
  76. }
  77. else {
  78. $("#menu dt a").removeClass();
  79. $(this).addClass("selected");
  80. $("#menu dd:visible").slideUp(200);
  81. $(this).parent().next().slideDown(220);
  82. }
  83. return false;
  84. });
  85. }
  86.  
  87. });
  88. </script>
  89. </head>
  90. <body>
  91. <!-- #container -->
  92. <div id="container">
  93. <!-- #menu -->
  94. <div id="menu">
  95. <dl>
  96. <dt id="item-1" class="first">
  97. <a href="#">ITEM 1</a>
  98. </dt>
  99. <dd id="sitem-1">
  100. <ul>
  101. <li><a href="#">item 1-1</a></li>
  102. <li><a href="#">item 1-2</a></li>
  103. <li><a href="#">item 1-3</a></li>
  104. <li><a href="#">item 1-4</a></li>
  105. </ul>
  106. </dd>
  107. <dt id="item-2">
  108. <a href="#">ITEM 2</a>
  109. </dt>
  110. <dd id="sitem-2">
  111. <ul>
  112. <li><a href="#">item 2-1</a></li>
  113. <li><a href="#">item 2-2</a></li>
  114. <li><a href="#">item 2-3</a></li>
  115. <li><a href="#">item 2-4</a></li>
  116. </ul>
  117. </dd>
  118. <dt id="item-3">
  119. <a href="#">ITEM 3</a>
  120. </dt>
  121. <dd id="sitem-3">
  122. <ul>
  123. <li><a href="#">item 3-1</a></li>
  124. <li><a href="#">item 3-2</a></li>
  125. <li><a href="#">item 3-3</a></li>
  126. <li><a href="#">item 3-4</a></li>
  127. </ul>
  128. </dd>
  129. <dt id="item-4">
  130. <a href="#">ITEM 4</a>
  131. </dt>
  132. <dd id="sitem-4" class="last">
  133. <ul>
  134. <li><a href="#">item 4-1</a></li>
  135. <li><a href="#">item 4-2</a></li>
  136. <li><a href="#">item 4-3</a></li>
  137. <li><a href="#">item 4-4</a></li>
  138. </ul>
  139. </dd>
  140. </dl>
  141. </div><!-- END #menu -->
  142. </div><!-- END #container -->
  143. </body>
  144. </html>

Report this snippet 

You need to login to post a comment.