Home arrow JavaScript arrow Page 2 - Using the YUI Menu Control
JAVASCRIPT

Using the YUI Menu Control


I recently wrote an article that gave a general overview of the Yahoo! User Interface library, or YUI. It's a comprehensive library of utilities and controls written in AJAX for developers like you. Using it can save you time and frustration and throughout the course of this article, I'll be looking at just how easy it is to create a functional, attractive and effective navigation menu, using nothing but a little HTML and the library.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 20
May 02, 2007
TABLE OF CONTENTS:
  1. · Using the YUI Menu Control
  2. · Creating a Basic Menu
  3. · Rendering and Displaying the Menu
  4. · Changing the Styling

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the YUI Menu Control - Creating a Basic Menu
(Page 2 of 4 )

Now that we have the files we need, we can create a basic menu. In a new page in your text editor create the following basic page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 
<head>
   
<title>YUI Menu Control</title>
 
</head>
 
<body>
   
<h1>YUI Menu Control Example</h1>
  
</body>
</html>

Save this as yuimenu.html. Next we need to reference the files that that the YUI menu control needs in order to work. Add the following <link> and <script> tags to the <head> of the above document:

<link rel="stylesheet" type="text/css" rel="nofollow" target="_blank" href = "yui/fonts-min.css">
<link rel="stylesheet" type="text/css" rel="nofollow" target="_blank" href = "yui/assets/menu.css">
<script type="text/javascript" src="yui/yahoo-dom-event.js"></script>
<script type="text/javascript" src="yui/container_core-min.js"></script>
<script type="text/javascript" src="yui/menu-min.js"></script>

Now we can start creating the menu. Creating the menu is extremely easy and can be done using either a standard unordered list in HTML or entirely via JavaScript. This example will look at using standard markup to create the menu. The root element of the menu must be a <div> element and the internal DOM is based on a simple <ul> element, with each menu item defined as an <li> element. A basic menu may appear as follows:

<div id="mymenu" class="yuimenu">
  <div class="bd">
   
<ul class="first-of-type">
     
<li class="yuimenuitem"><a rel="nofollow" target="_blank" href = "aboutus.htm">About Us</a></li>
     
<li class="yuimenuitem"><a rel="nofollow" target="_blank" href = "products.htm">Products</a></li>
     
<li class="yuimenuitem"><a rel="nofollow" target="_blank" href = "myaccount.htm">My Account</a></li>
     
<li class="yuimenuitem"><a rel="nofollow" target="_blank" href = "developer.htm">Developer Connection</a></li>
     
<li class="yuimenuitem"><a rel="nofollow" target="_blank" href = "partners.htm">Our Partners</a></li>
     
<li class="yuimenuitem"><a rel="nofollow" target="_blank" href = "sitemap.htm">Sitemap</a></li>
   
</ul>
 
</div>
</div>

So we have a <div> element that forms the root of our menu. It needs an id so it can be addressed via the script, and should have the default class of yuimenu to give it some basic formatting. The nested <div> acts as the container for the menu and ensures that the menu is only as wide as it needs to be (take this away and it stretches across the entire browser window). The <ul> is given the class first-of-type for styling purposes, and any items we want in the menu are added as <li> elements with nested link elements. The <li> elements should all have the yuimenuitem class.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks
- Dynamic jQuery Styling

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials