YUI Library Examples: Menu Family: Application Menubar

Menu Family: Application Menubar

This example demonstrates how to use the MenuBar widget to create a menu bar entirely from JavaScript that functions like one found in a traditional desktop application.

Begin by defining an array of MenuItem configuration properties that describe each item in the MenuBar.

Next use the onDOMReady method of the Event utility to instantiate the MenuBar as soon as the page's DOM is available for scripting.

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. The "itemdata" property is set to the array of MenuItem configuration properties; each item in the array will be used to add a new item to the MenuBar when it is rendered. Lastly, it is necessary to add a "show" event handler to keep the position of the first, left-most submenu positioned flush to the edge of the browser's viewport. This is because by default Menu instances try to keep themselves positioned 10 pixels away from the edge of the browser viewport.

Often the first item in a menu bar has an icon as its label, but no text. It is easy to achieve this using CSS, while still ensuring the text of the MenuItem is available to users of a screen reader.

Start by wrapping the MenuItem's text label in an <em> element. Next, give the <em> a fixed width, and set the "text-indent" property to a value that pushes the text beyond the boundaries of the width. Use the "overflow" property to hide the text. Lastly, apply an image to the MenuItem instance via the "background" property.

Menu Family Examples:

More Menu Family Resources:

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings