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.
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 element as defined by the width. Use the "overflow"
property to hide the text. Lastly, apply an image to the MenuItem instance via the
"background" property.
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 © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings