This example demonstrates how to create a traditional, two-column page layout (using Grids) with an set of animated fly-out menu navigation in the left column. The left navigation is created using a Menu instance that is constructed using existing markup and enables the user to navigate to different landing pages for each Yahoo! product category. If JavaScript is enabled, submenus are appended to the items in the Menu, allowing the user to skip the product landing pages and proceed directly to a given property.
Begin by placing the markup for the two-column Grid on the page (this example uses the Grids Preset Template 1, 160px left). Next add the Menu markup for the root Menu instance to the left column of the grid.
1 | <div id="productsandservices" class="yuimenu"> |
2 | <div class="bd"> |
3 | <ul class="first-of-type"> |
4 | <li class="yuimenuitem"> |
5 | <a class="yuimenuitemlabel" href="#communication">Communication</a> |
6 | </li> |
7 | <li class="yuimenuitem"> |
8 | <a class="yuimenuitemlabel" href="http://shopping.yahoo.com">Shopping</a> |
9 | </li> |
10 | <li class="yuimenuitem"> |
11 | <a class="yuimenuitemlabel" href="http://entertainment.yahoo.com">Entertainment</a> |
12 | </li> |
13 | <li class="yuimenuitem"> |
14 | <a class="yuimenuitemlabel" href="#">Information</a> |
15 | </li> |
16 | </ul> |
17 | </div> |
18 | </div> |
view plain | print | ? |
Use the onContentReady
method of the Event utility to instantiate the Menu as soon as
its markup is available for scripting.
1 | /* |
2 | Initialize and render the Menu when its elements are ready |
3 | to be scripted. |
4 | */ |
5 | |
6 | YAHOO.util.Event.onContentReady("productsandservices", function () { |
7 | |
8 | /* |
9 | Instantiate a Menu: The first argument passed to the |
10 | constructor is the id of the element in the page |
11 | representing the Menu; the second is an object literal |
12 | of configuration properties. |
13 | */ |
14 | |
15 | var oMenu = new YAHOO.widget.Menu( |
16 | "productsandservices", |
17 | { |
18 | position: "static", |
19 | hidedelay: 750, |
20 | lazyload: true, |
21 | effect: { |
22 | effect: YAHOO.widget.ContainerEffect.FADE, |
23 | duration: 0.25 |
24 | } |
25 | } |
26 | ); |
27 | |
28 | }); |
view plain | print | ? |
This Menu 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 Menu 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. The "lazyload" property is set to "true" to help speed up the initial load time of the Menu instance by deferring the initialization and rendering of each submenu until just before it is initially made visible. Lastly, the effect configuration property is set to use the pre-canned FADE ContainerEffect instance bundled with the Container Core package to animate each submenu's opacity as it is shown and hidden.
Submenus are added to each item in the Menu by subscribing to the "beforeRender" event and setting the "submenu" configuration property of each MenuBarItem instance to an object literal containing the necessary data to create the submenu.
1 | /* |
2 | Define an array of object literals, each containing |
3 | the data necessary to create a submenu. |
4 | */ |
5 | |
6 | var aSubmenuData = [ |
7 | |
8 | { |
9 | id: "communication", |
10 | itemdata: [ |
11 | { text: "360", url: "http://360.yahoo.com" }, |
12 | { text: "Alerts", url: "http://alerts.yahoo.com" }, |
13 | { text: "Avatars", url: "http://avatars.yahoo.com" }, |
14 | { text: "Groups", url: "http://groups.yahoo.com " }, |
15 | { text: "Internet Access", url: "http://promo.yahoo.com/broadband" }, |
16 | { |
17 | text: "PIM", |
18 | submenu: { |
19 | id: "pim", |
20 | itemdata: [ |
21 | { text: "Yahoo! Mail", url: "http://mail.yahoo.com" }, |
22 | { text: "Yahoo! Address Book", url: "http://addressbook.yahoo.com" }, |
23 | { text: "Yahoo! Calendar", url: "http://calendar.yahoo.com" }, |
24 | { text: "Yahoo! Notepad", url: "http://notepad.yahoo.com" } |
25 | ] |
26 | } |
27 | |
28 | }, |
29 | { text: "Member Directory", url: "http://members.yahoo.com" }, |
30 | { text: "Messenger", url: "http://messenger.yahoo.com" }, |
31 | { text: "Mobile", url: "http://mobile.yahoo.com" }, |
32 | { text: "Flickr Photo Sharing", url: "http://www.flickr.com" }, |
33 | ] |
34 | }, |
35 | |
36 | { |
37 | id: "shopping", |
38 | itemdata: [ |
39 | { text: "Auctions", url: "http://auctions.shopping.yahoo.com" }, |
40 | { text: "Autos", url: "http://autos.yahoo.com" }, |
41 | { text: "Classifieds", url: "http://classifieds.yahoo.com" }, |
42 | { text: "Flowers & Gifts", url: "http://shopping.yahoo.com/b:Flowers%20%26%20Gifts:20146735" }, |
43 | { text: "Real Estate", url: "http://realestate.yahoo.com" }, |
44 | { text: "Travel", url: "http://travel.yahoo.com" }, |
45 | { text: "Wallet", url: "http://wallet.yahoo.com" }, |
46 | { text: "Yellow Pages", url: "http://yp.yahoo.com" } |
47 | ] |
48 | }, |
49 | |
50 | { |
51 | id: "entertainment", |
52 | itemdata: [ |
53 | { text: "Fantasy Sports", url: "http://fantasysports.yahoo.com" }, |
54 | { text: "Games", url: "http://games.yahoo.com" }, |
55 | { text: "Kids", url: "http://www.yahooligans.com" }, |
56 | { text: "Music", url: "http://music.yahoo.com" }, |
57 | { text: "Movies", url: "http://movies.yahoo.com" }, |
58 | { text: "Radio", url: "http://music.yahoo.com/launchcast" }, |
59 | { text: "Travel", url: "http://travel.yahoo.com" }, |
60 | { text: "TV", url: "http://tv.yahoo.com" } |
61 | ] |
62 | }, |
63 | |
64 | { |
65 | id: "information", |
66 | itemdata: [ |
67 | { text: "Downloads", url: "http://downloads.yahoo.com" }, |
68 | { text: "Finance", url: "http://finance.yahoo.com" }, |
69 | { text: "Health", url: "http://health.yahoo.com" }, |
70 | { text: "Local", url: "http://local.yahoo.com" }, |
71 | { text: "Maps & Directions", url: "http://maps.yahoo.com" }, |
72 | { text: "My Yahoo!", url: "http://my.yahoo.com" }, |
73 | { text: "News", url: "http://news.yahoo.com" }, |
74 | { text: "Search", url: "http://search.yahoo.com" }, |
75 | { text: "Small Business", url: "http://smallbusiness.yahoo.com" }, |
76 | { text: "Weather", url: "http://weather.yahoo.com" } |
77 | ] |
78 | } |
79 | ]; |
80 | |
81 | |
82 | // Subscribe to the Menu instance's "beforeRender" event |
83 | |
84 | oMenu.subscribe("beforeRender", function () { |
85 | |
86 | if (this.getRoot() == this) { |
87 | |
88 | this.getItem(0).cfg.setProperty("submenu", aSubmenuData[0]); |
89 | this.getItem(1).cfg.setProperty("submenu", aSubmenuData[1]); |
90 | this.getItem(2).cfg.setProperty("submenu", aSubmenuData[2]); |
91 | this.getItem(3).cfg.setProperty("submenu", aSubmenuData[3]); |
92 | |
93 | } |
94 | |
95 | }); |
96 | |
97 | |
98 | /* |
99 | Call the "render" method with no arguments since the |
100 | markup for this Menu instance is already exists in the page. |
101 | */ |
102 | |
103 | oMenu.render(); |
view plain | print | ? |
Finally, it is necessary to set the "position" CSS property of the root Menu
instance's element (<div id="#productsandservices">
) to
"static" to match that of the "position" configuration property.
1 | #productsandservices { |
2 | |
3 | position: static; |
4 | |
5 | } |
view plain | print | ? |
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings