
Home
Menu and Navigation
Multiple Level
Menus
Here
|
Categories
Partners
DaniWeb is an exciting community for web developers, Internet marketers, and technology enthusiasts.
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE6+ Opera8+
Smooth Navigational Menu (v1.31)Author:
Updated: July 27th, 09" (v1.31): Fixed bug so shadows can be disabled if desired. Description: Smooth Navigation Menu is a multi level, CSS list based menu powered using jQuery that makes website navigation a smooth affair. And that's a good thing given the important role of this element in any site. The menu's contents can either be from direct markup on the page, or an external file and fetched via Ajax instead. And thanks to jQuery, a configurable, sleek "slide plus fade in" transition is applied during the unveiling of the sub menus. The menu supports both the horizontal and vertical (sidebar) orientation. Note that the sub menus reposition themselves if too close to the window's right edges. The depth of the accompanying shadow can be customized, or removed altogether. Smooth we say! Step 1: Insert the following code into the <head> section of your page: The above code references a few external files, which by default you should upload to the same directory as the page itself (right click each file and select "Save As"): Step 2: Add the below menu code to the BODY section of your page. It contains the markup for 1 horizontal menu and 1 vertical menu: Each menu should consist of an outer DIV and a valid UL list contained inside it. If you wish the menu content to reside in an external file on your server and dynamically added to your page(s), read the section "Putting the Menu contents in an external file" below. Well, that's it for installation.
|
| Attribute | Description |
mainmenuid |
The ID of the menu's outermost DIV. If the menu contents are fetched via Ajax, then this ID should correspond to the outermost DIV that's within the external file. |
orientation |
Sets the orientation of the menu. Enter the
value "h" or "v" for a horizontal or vertical menu, respectively. Note
that the "classname" setting below must also be set
according to the "orientation" setting. |
classname |
Sets the CSS class name that gets applied to
the outermost DIV of the menu, effectively styling it. Based on the "orientation"
setting above, you want to enter the CSS class that correctly styles the
menu By default, "ddsmoothmenu" creates a horizontal menu
bar, while "ddsmoothmenu-v" creates a vertical one. Take a
look inside
ddsmoothmenu.css and
ddsmoothmenu-v.css. |
customtheme |
In general, customizing the menu's style and background colors
is done by editing the two CSS files of the script.
However, you can also modify the menu's background and hover background
color- on
a per page or per menu basis easily, by taking advantage of the "customtheme"
setting. To do so, uncomment (remove the // prefix) from
this setting and declare two CSS background values, one for the default state, the
other, when the mouse rolls over the menu items:customtheme: ["#1c5a80", "#18374a"], //override default menu CSS background values? Uncomment: ["normal_background", "hover_background"] This property is useful for quickly testing out color combinations without having to edit "ddsmoothmenu.css" each time. |
contentsource |
Enter "markup" if your
menu contents are directly inline on the page, or ["container_id",
"path_to_menu_file"] For more info on the later option, see "Putting the Menu contents in an external file and fetched using Ajax"
below. |
As far as the HTML markup of each menu, it should consist of an outer DIV plus a valid UL list inside it, such as:
<div id="smoothmenu1">
<ul>
<li><a href="http://www.dynamicdrive.com">Item 1</a></li>
<li><a href="#">Folder 0</a>
<ul>
<li><a href="#">Sub Item 1.1</a></li>
<li><a href="#">Sub Item 1.2</a></li>
</ul>
</li>
</ul>
</div>
Make sure the UL list is valid You can use W3C's validation service to quickly check your HTML list for incorrectly nested or unclosed tags.
Instead of the menu's content being direct markup on the page, you can instead put that HTML in an external file on your server and have the menu dynamically added to the BODY of your page using Ajax. The above menu is embedded this way. The process for this is simple enough:
ddsmoothmenu.init() is run. You can
include any HTML within this empty container that you may want shown to
search engines or users with JavaScript disabled, as it will be replaced
when the script is run.ddsmoothmenu.init()'s "contentsource"
setting to the appropriate setting :The path to the external file, in this case "smoothmenu.htm", should be a relative path to it based on the current page's position within your site.
When the user rolls over a menu item (LI element) that contains a sub menu
(UL element), the script dynamically adds a CSS class of ".selected"
to the former's inner A element. This allows you to style the current active
menu item differently from the rest. Inside "ddsmoothmenu.css",
the relevant CSS you'll want to tweak is:
.ddsmoothmenu ul li a.selected{ /*CSS class that's
dynamically added to the currently active menu items' LI A element*/
background: black;
color: white;
}
Finally inside ddsmoothmenu.js there are a few global settings you can modify, such as setting the paths to the arrow images, speed of animation, and whether to disable shadows:
//Specify full URL to down and right arrow images (23
is padding-right added to top level LIs with drop downs):
arrowimages: {down:['downarrowclass', 'down.gif', 23], right:['rightarrowclass',
'right.gif']},
transition: {overtime:300, outtime:300}, //duration of slide in/ out animation,
in milliseconds
shadow: {enabled:true, offsetx:5, offsety:5},