School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

JavaScript Source Code


Welcome to Dream.In.Code
Become an Expert!

Join 339,903 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,589 people online right now. Registration is fast and FREE... Join Now!




Drop down (overlapping) menu

Create a menu with the same style as the "Member Panel" on DIC. (Example including Javascript, CSS and HTML)

Submitted By: William_Wilson
Actions:
Rating:
Views: 4,463

Language: JavaScript

Last Modified: May 6, 2007
Instructions: This snippet works because of Javascript, thus I have posted it here, but it really requires more explanation, so I have included an example implementation, including javascript, css, and HTML needed.
I have also, used 2 images of up and down arrows, but the alt will work until you feel more comfortable with the example.

Snippet


  1. function ShowPanel()
  2. {
  3.      if (document.getElementById('panel').style.display == 'block')
  4.      {
  5.           document.getElementById('panel').style.display = 'none';
  6.           document.getElementById('up_down').src = "./down.gif";
  7.      }
  8.      else
  9.      {
  10.           document.getElementById('panel').style.display = 'block';
  11.           document.getElementById('up_down').src = "./up.gif";
  12.      }
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. //Example HTML:
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  22.  
  23. <html>
  24. <head>
  25.      <link rel="stylesheet" type="text/css" href="./style.css">
  26. </head>
  27. <body>
  28.  
  29. <script language="Javascript">
  30. <!--
  31.  
  32.      function ShowPanel()
  33.      {
  34.           if (document.getElementById('panel').style.display == 'block')
  35.           {
  36.                document.getElementById('panel').style.display = 'none';
  37.                document.getElementById('up_down').src = "./down.gif";
  38.           }
  39.           else
  40.           {
  41.                document.getElementById('panel').style.display = 'block';
  42.                document.getElementById('up_down').src = "./up.gif";
  43.           }
  44.      }
  45. //-->
  46. </script>
  47.  
  48. <div id="menu_title">
  49.  
  50. <menu_head>
  51.      <!-- (title bar) - defines width of menu //-->
  52. </meun_head>
  53. <table>
  54.      <tr>
  55.           <td width="150">
  56.                <b>Drop Down Menu Title</b>
  57.           </td>
  58.           <td>
  59.                <a href="#" onclick="ShowPanel();">
  60.                     <img id="up_down" src="./down.gif" alt="V">
  61.                </a>
  62.           </td>
  63.      </tr>
  64. </table>
  65.  
  66. <menu_body>
  67.      <!-- (items displayed on drop down) //-->
  68. </menu_body>
  69. <div id="panel">
  70. <hr>
  71.  
  72.      <a href="http://www.google.com">Google</a>
  73.      <br>
  74.      <a href="http://www.dreamincode.net">Dream In Code</a><br>
  75.  
  76. <hr>
  77.  
  78. <table>
  79.      <form action="?" method="post"></form>
  80.      <tr>
  81.           <td>User Name:</td>
  82.      </tr>
  83.      <tr>
  84.           <td>
  85.                <input type = "text" class="input_text" name="username" id="username" value="">
  86.           </td>
  87.      </tr>
  88.      <tr>
  89.           <td>Password:</td>
  90.      </tr>
  91.      <tr>
  92.           <td>
  93.                <input type="password" class="input_text" name="password" id="password" value="">
  94.           </td>
  95.      </tr>
  96.      <tr>
  97.           <td align="right" height="25" valign="top">
  98.                <input type="submit" class="button" value="Login">
  99.           </td>
  100.      </tr>
  101.  
  102. </table>
  103. </div>
  104. </div>
  105.  
  106. </body>
  107. </html>
  108.  
  109.  
  110.  
  111. //script.css:
  112. a img
  113. {
  114.      border: 0;
  115.      padding-top: 2px;
  116.      padding-right: 2px;
  117. }
  118.  
  119. a:active
  120. {
  121.      padding-left: 5px;
  122.      color: #000000;
  123. }
  124.  
  125. a:link
  126. {
  127.      padding-left: 5px;
  128.      color: #000000;
  129. }
  130.  
  131. a:visited
  132. {
  133.      padding-left: 5px;
  134.      color: #000000;
  135. }
  136.  
  137. body
  138. {
  139.      font: 9pt Arial, Verdana, Sans-Serif;
  140.      background: #FFFFFF;
  141.      color: #000000;
  142. }
  143.  
  144. .button
  145. {
  146.      margin-top: 5px;
  147. }
  148.  
  149. hr
  150. {
  151.      max-height: 1px;
  152.      height: 1px;
  153.      color: #000000;
  154.      border-style: solid;
  155. }
  156.  
  157. input
  158. {
  159.      border: 1px solid #00009E;
  160.      font-size: 10px;
  161.      font-family: Verdana;
  162. }
  163.  
  164. .input_text
  165. {
  166.      background-color: #FFFF94;
  167.      vertical-align: middle;
  168.      width: 138px;
  169. }
  170.  
  171. #menu_title
  172. {
  173.      width: 150px;
  174.      height: 25px;
  175.      background-color: #FBA000;
  176.      opacity: 0.8;
  177.      -moz-opacity: 0.8;
  178.      filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80);
  179.      position: fixed;
  180.      top:  0px;
  181.      left: 0px;
  182.      margin-top:  5px;
  183.      margin-left: 5px;
  184.      padding: 2px;
  185. }
  186.  
  187. #panel
  188. {
  189.      display: none;
  190.      position: fixed;
  191.      top: 28px;
  192.      background-color: #FBA000;
  193.      width: 150px;
  194.      margin-left: 5px;
  195.      left: 0px;
  196.      margin-top: 0px;
  197.      padding: 2px;
  198. }
  199.  
  200. #panel a
  201. {
  202.      text-decoration:none;
  203.      font-weight:bold;
  204.      line-height:150%;
  205. }
  206.  
  207. table
  208. {
  209.      border: none;
  210.      padding: 0;
  211.      spacing: 0;
  212. }

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month