Home arrow JavaScript arrow Building a Dynamic Menu with CSS and JavaScript, part 1
JAVASCRIPT

Building a Dynamic Menu with CSS and JavaScript, part 1


Dynamic menus that highlight the link where a website visitor is located can make site navigation a much more pleasant experience. In this article, the first in a series, we will cover the construction process of a dynamic menu, extensively using the DOM methods within user-defined JavaScript objects to help us learn how to build more complex structures.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 67
June 22, 2005
TABLE OF CONTENTS:
  1. · Building a Dynamic Menu with CSS and JavaScript, part 1
  2. · Coding the menu: CSS and HTML into action
  3. · The dynamic factor
  4. · The "menu" JavaScript object

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building a Dynamic Menu with CSS and JavaScript, part 1
(Page 1 of 4 )

In the ever-growing world of the Web, dynamic sites have found a well established position that expands design possibilities and makes maintenance and updating tasks a relatively painless experience. The maintenance of an equilibrium between server-side and client-side technologies is a fundamental concept for offering a professional, well-polished site to visitors who are always looking for new content and elegant visual presentation. Particularly, in the current client-side arena, one of the most used tools to spice up websites a little more is the implementation of dynamic drop-down/pull-down menus, facilitating the overall navigation process to users.

Certainly we might go deeper into the subject of client-side dynamic menus and explore some of the underlying techniques for building complex menu structures. However, sometimes there is no need to get so technical for building dynamic menus. That’s our trusted bet for this article series. We’re going to build a dynamic navigation menu that will identify the active page, and accordingly display the link differently from the others, making it easier for the user to navigate through the site. Hopefully the techniques used will serve as an introduction for working with user-defined objects in JavaScript and their correct implementation in Web pages. Just keep reading to give that dynamic touch to your site!

The migrating process: from static to dynamic

In order to establish a starting point for building the dynamic menu, let’s first create a conventional static navigation system, using pure CSS and HTML markup, which might nicely suit the navigational needs for quite simple websites. I’ve chosen to give the menu a rather temperate look, using only three small background images, but surely you’ll want to change this to satisfy your personal taste. Since one picture is worth a thousand words, here’s the initial appearance for the static menu:

 

 

 

Not too bad, eh? As you can see, the navigation menu is really simple, but appealing enough to be easily implemented on Web documents. Since I’ll be progressively building the dynamic menu, this is the way it will look, for instance, when the user is located at the "about us" page:

 

 

 

Before we go deeper into the always-uncertain territory of code, as mentioned previously, I’ve used three background images for the menu. The first one I’ve created is used for the menu’s left corner and is depicted below:

 

 

 

Next, I’ve generated the second background image to give the beveled appearance of the menu. Its dimensions are 1px wide and 32px high. It’s really small, but I'll show it anyway, so you get the idea of how it works for achieving the visual effect. Here it is:

 

 

Finally, the remaining background image is used to create the right corner of the menu, in a similar way to what I did with the left corner. Here’s the corresponding image:

 

 

Well, now that I’ve shown the background images to be used in the navigation menu, I guess you’ve grasped the general idea of how the images will be employed to build the menu's appearance. It’s time to take a look at the corresponding code. 


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 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials