Smooth Navigational Menu (ddsmoothmenu.js)

A lightweight jQuery plugin that creates smooth, animated drop-down menus for horizontal or vertical navigation. Originally developed by Dynamic Drive and released in 2008, it supports both markup-based and AJAX-loaded menus, optional drop shadows, configurable animation timings, and custom theming.


✨ Key Features

  • Horizontal & Vertical Modes
    Toggle between a top-bar menu or sidebar by setting the orientation option.
  • AJAX-Loaded Menus
    Load menu markup from an external file into a container DIV.
  • Animated Show/Hide
    Configure slide/fade durations and delays for submenu appearance.
  • Optional Shadows
    Add drop shadows to submenus (disabled automatically in IE6).
  • Custom Themes
    Override default background colors without touching CSS files.

🛠 Dependencies & Compatibility

  • jQuery (1.x – 3.x)
  • Modern Browsers (IE7+, Chrome, Firefox, Safari, Edge)
  • IE6: JavaScript detects and disables shadows for compatibility

⚙️ Configuration Options

Below are the primary settings you can pass to ddsmoothmenu.init():

Option Default Description
arrowimages.down ['downarrowclass','down.gif', 23] CSS class, image filename & right-padding for top-level dropdown arrows.
arrowimages.right ['rightarrowclass','right.gif'] CSS class & image filename for nested submenu arrows.
transition.overtime 0 Duration (ms) for submenu show animation.
transition.outtime 0 Duration (ms) for submenu hide animation.
shadow.enable true Enable drop-shadow effects.
shadow.offsetx 5 Horizontal offset (px) for the shadow.
shadow.offsety 5 Vertical offset (px) for the shadow.
showhidedelay.showdelay 0 Delay (ms) before showing a submenu.
showhidedelay.hidedelay 0 Delay (ms) before hiding a submenu.

Defaults taken from the core file .


🚀 Initialization

Include jQuery and ddsmoothmenu.js, then call:

ddsmoothmenu.init({
  mainmenuid:   "nav-user",     // ID of DIV containing the <ul>
  orientation:  'h',            // 'h' = horizontal, 'v' = vertical sidebar
  classname:    'ddsmoothmenu', // Class added to outer DIV
  contentsource:"markup"        // "markup" or [containerID, externalFile]
});

This example is taken from meta.php where the plugin is applied to a user-nav bar .


🔍 How It Works

flowchart TD
  A[Page Load] --> B[ddsmoothmenu.init(settings)]
  B --> C[jQuery DOM Ready]
  C --> D{contentsource == "markup"?}
  D -->|markup| E[buildmenu: parse existing <ul>]
  D -->|array| F[getajaxmenu: AJAX fetch external HTML]
  E & F --> G[Attach hover handlers to LIs]
  G --> H[Hover → animate submenu show/hide]
  1. Initialization
    Processes custom theming and IE6 shadow settings.
  2. Menu Construction
    • Markup mode: Scans existing <ul> structure.
    • AJAX mode: Loads remote HTML into a container, then builds.
  3. Event Binding
    Adds mouseenter/mouseleave handlers to LI headers.
  4. Animation & Shadows
    Shows/hides submenus with slide/fade and optional shadows.

🔧 Public API Methods

Method Description
init(setting) Entry point: configures, then builds or fetches menu on document.ready.
buildmenu($, setting) Parses markup <ul>, computes dimensions, sets up DOM & events.
getajaxmenu($, setting) Loads external HTML via AJAX into a container, then calls buildmenu.

📄 Markup Example

<div id="nav-user" class="ddsmoothmenu">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Products</a>
      <ul>
        <li><a href="#">Product A</a></li>
        <li><a href="#">Product B</a></li>
      </ul>
    </li>
    <li><a href="#">Contact</a></li>
  </ul>
</div>
  1. Wrap a <ul> inside a DIV with an ID (matches mainmenuid).
  2. Nested <ul> elements represent submenus.

🎨 Custom Theming

Pass a customtheme array of two CSS colors to override default link backgrounds:

ddsmoothmenu.init({
  ...,
  customtheme: ["#1c5a80", "#18374a"]
});

This injects a <style> block for default and hover states.


💡 Tips & Best Practices

  • CSS First: Define base styles for .ddsmoothmenu ul li a before including the script.
  • Image Paths: Ensure down.gif and right.gif are located relative to your HTML page.
  • Accessibility: Provide meaningful link text; submenus degrade gracefully if JS is disabled.
  • Performance: Minimize transition.overtime/outtime for snappy UX.

Ready to enhance your navigation? 🚀
For more customization and updates, visit Dynamic Drive’s ddsmoothmenu page.