This example demonstrates how to create a traditional, two-column page layout (using Grids) with top navigation featuring drop-down menus. The top navigation is created using a MenuBar instance that is constructed using existing markup and enables the user to navigate to different landing pages for each Yahoo! product category.
Begin by placing the markup for the two-column Grid on the page (this example uses the Grids Preset Template 1, 160px left). Add the markup for the MenuBar instance to the right column of the grid, appending the class of "yuimenubarnav" to the root element. The application of the "yuimenubarnav" class will render each item in the MenuBar instance with arrows to the right of each text label, providing a visual cue that the item contains a submenu.
1 | <div id="productsandservices" class="yuimenubar yuimenubarnav"> |
2 | <!-- Additional Menubar markup here --> |
3 | </div> |
view plain | print | ? |
Use the onContentReady
method of the Event utility to instantiate the MenuBar as soon as
its markup is available for scripting.
1 | /* |
2 | Initialize and render the MenuBar when its elements are ready |
3 | to be scripted. |
4 | */ |
5 | |
6 | YAHOO.util.Event.onContentReady("productsandservices", function () { |
7 | |
8 | /* |
9 | Instantiate a MenuBar: The first argument passed to the |
10 | constructor is the id of the element in the page |
11 | representing the MenuBar; the second is an object literal |
12 | of configuration properties. |
13 | */ |
14 | |
15 | var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", { |
16 | autosubmenudisplay: true, |
17 | hidedelay: 750, |
18 | lazyload: true }); |
19 | |
20 | /* |
21 | Call the "render" method with no arguments since the |
22 | markup for this MenuBar instance is already exists in |
23 | the page. |
24 | */ |
25 | |
26 | oMenuBar.render(); |
27 | |
28 | }); |
view plain | print | ? |
This MenuBar instance makes use of several configuration properties. Setting the "autosubmenudisplay" configuration property to "true" modifies its default behavior so that mousing over any item in the MenuBar automatically triggers the display of its submenu. The "hidedelay" configuration property is set to "750" so each submenu automatically hides 750ms after the user's mouse has left the menu. Lastly, the "lazyload" property is set to "true" to help speed up the initial load time of the MenuBar instance by deferring the initialization and rendering of each submenu until just before it is initially made visible.
You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings