JavaScript
  Home arrow JavaScript arrow Building a Dynamic Menu with CSS and JavaS...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Building a Dynamic Menu with CSS and JavaScript, part 1
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 53
    2005-06-22

    Table of Contents:
  • Building a Dynamic Menu with CSS and JavaScript, part 1
  • Coding the menu: CSS and HTML into action
  • The dynamic factor
  • The "menu" JavaScript object

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building a Dynamic Menu with CSS and JavaScript, part 1


    (Page 1 of 4 )

    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.

    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. 

    More JavaScript Articles
    More By Alejandro Gervasio


       · The article shows how to define a simple dynamic navigational menu going from a...
       · Hello Sir,First of all congrates that u built this useful menu .I created this...
       · Thank you for the kind comments on my article. With reference to your question, the...
       · Thanks for a well-written tutorial!I came across this tutorial when searching for...
       · Glad to know my article has been useful to you, but unfortunately since I wrote it...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT