Download list based DHTML menu

Demo | Demo by Moderator Chris

Bookmark and Share

Licensing

This script is distributed under the LGPL open source license.
Commercial licenses are also available. Some of these licenses also includes personal e-mail support for up to 1 year.

Use a strict or loose doctype

This menu requires a valid doctype in order to look good in Opera. You can either choose the strict doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
or a loose doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Choose the one that makes your page look best across different browsers. The doctype tag should be placed on the first line of your HTML file.

Put this into your <HEAD> section

Put this into your <BODY> section

Configuration

This menu is completely list based. It means that you build the menu by creating a <UL><LI> list. This is how the menu code could look like:
<div id="dhtmlgoodies_menu">
  <ul>
    <li><a href="#">Menu item 1</a></li>
    <li><a href="#">Menu item 2</a>
      
      <ul>
        <li><a href="#">Sub item 1</a></li>
        <li><a href="#">This is a sub</a></li>
        <li><a href="#">Sub item 3</a>
          <ul>
            <li><a href="#">Sub item 3.1</a></li>
            <li><a href="#">Sub item 3.2</a>
              <ul>
                <li><a href="#">Sub item 3.2.1</a></li>
                <li><a href="#">Sub item 3.2.2</a></li>
                <li><a href="#">Sub item 3.2.3</a></li>
              </ul>
            </li>
            <li><a href="#">Sub item 3.3</a></li>
          </ul>
        </li>
        <li><a href="#">Sub item 4</a></li>
        <li><a href="#">Sub item 5</a></li>
      </ul>
    </li>
    <li><a href="#">Menu item 3</a>
      <ul>
        <li><a href="#">Sub item 3.1</a></li>
        <li><a href="#">Sub item 3.2</a></li>
        <li><a href="#">Sub item 3.3</a></li>
        <li><a href="#">Sub item 3.4</a></li>
      </ul>  
    </li>
    <li><a href="#">Menu item 4</a>
    <li><a href="#">Menu item 5</a>
  </ul>
  </div>

Note that:

  • You need the <div id="dhtmlgoodies_menu"> as parent element of the unordered list
  • Each menu item should have this structure: <LI><A>...</A></LI>. I.e: A list item followed by an anchor tag. Use an empty href if you don't want a link on the menu item.

Adding styles to the menu

You use CSS(Cascading Style Sheet) to configure how the menu should look like. Example:
#dhtmlgoodies_menu ul.menuBlock1{  /* Menu bar - main menu items */
  border:0px;
  padding:3px;
  border:1px solid #317082;
  background-color:#E2EBED;
}
#dhtmlgoodies_menu ul.menuBlock2{  /* Menu bar - sub menu depth 1 */
  border:0px;
  padding:3px;
  border:1px solid #555;
}

The classes menuBlock1,menuBlock2 ... are used to apply styles to a group of menu items. Example: menuBlock1 specifies general styles for the group of main menu items(the <UL> tag), while menuBlock2 applies to all sub elements that are direct children of a main menu item.

There are some different classes for the specific menu items. Here's an example of this:
#dhtmlgoodies_menu .currentDepth1{
  padding-right:10px;
}
#dhtmlgoodies_menu .currentDepth1over{
  padding-right:10px;
  background-color:#317082;
  
}
#dhtmlgoodies_menu .currentDepth1over a{  /* Text rules */
  color:#FFF;
}

.currentDepth1 specifies a style for all main menu items(the <LI> tags). .currentDepth1over specifies rollover effects for all main menu items. .currentDepth1over a specifies rollover effects for main menu items(Text effects).

Download arrow

There's one image used in this script. That's the arrow indicating sub menu items. To download it, right click on the image below and select "Save target As". Put the image in a sub folder called images.

Javascript variables

There are two javascript variables which you could modify as you need. The first one specifies path to the arrow image:
var dhtmlgoodies_menu_arrow = 'images/arrow.gif';

The second one:
var timeBeforeAutoHide = 2000;
specifies how long the script should wait before it hides active menu items after the mouse cursor has moved away from the menu. The time is specified in microseconds(2000 = 2 seconds).

Rate this script at Hotscripts.com

If you like my script, please rate it at HotScripts.com

Comments

No one has commented this - be first!

Post your comment

Don't have an avatar? Create one at Gravatar.com.

Confirmation code:

Go to cbolson.com


About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2025 dhtmlgoodies.com