SunQuest
 
       JavaScript
  Home arrow JavaScript arrow Page 2 - Controllable Navigation Bars with JavaScri...
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  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
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

Controllable Navigation Bars with JavaScript, Part 1
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2005-03-21

    Table of Contents:
  • Controllable Navigation Bars with JavaScript, Part 1
  • Building core functionality
  • The JavaScript"switchBar()"function
  • Complete code listing and background images

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Controllable Navigation Bars with JavaScript, Part 1 - Building core functionality


    (Page 2 of 4 )

     

    To introduce ourselves to the process of creating a basic controllable sidebar, we’re going to define a three-column liquid layout. It will consist of a "navbar" <div> element positioned to the left of the document, a "container" <div> element centered on the page, and a third <div>, positioned to the right, defined as the "headlines" column. Finally, we’ll specify a "switchbar" selector, applied to a <div> element that will behave as a switcher for the "navbar" column, hiding it or displaying it according to the user’s actions.

     

    No "header" and "footer" sections will be included in the markup and CSS rules, in order to keep the code uncluttered. However, whether your layout needs fall under a two-column model or under other categories, the solution is perfectly adaptable. Once we’ve defined the basic guidelines for page layout, let’s start listing the CSS code:

     

    <style type="text/css">

    body {

        margin: 0;

    }

    #navbar {

        float: left;

        width: 15%;

        height: 600px;

        background: #ccf;

        padding: 10px;

        border-left: 1px solid #000;

        border-bottom: 1px solid #000;

    }

    #switchbar {

        float: left;

        width: 18px;

        height: 600px;

        background: #fff url("tab_left.gif")
    repeat-y center center;

        padding-top: 10px;

        padding-bottom: 10px;

    }

    #content {

        float: left;

        width: auto;

        padding: 10px;

        border-bottom: 1px solid #000;

    }

    #headlines {

        float: right;

        width: 15%;

        height: 600px;

        background: #ccf;

        padding: 10px;

        border-left: 1px solid #000;

        border-right: 1px solid #000;

        border-bottom: 1px solid #000;

    }

    </style>

     

    Taking a look at the above CSS declarations, we can see that the three main columns have been styled, defining background colors, borders and the like, following a momentary inspiration. Also, we’ve set temporary fixed heights for them, to show the visual effect of the example without needing to populate each column with content. This will be kept that way only for the moment. Our final approach will remove entirely the height properties. Remember that we’re using liquid design here. Lastly, here is a key concept to take into account: we’ve assigned a value of "auto" for the width of the "content" <div>, meaning that this element will expand and stretch over the page, according to the presence or absence of any column positioned to the left or the right. This value is very important to make the effect work seamlessly.

     

    Having explained the why of fixed heights, let’s have a look at the "switchbar" selector. We’ll be sticking this one to the switcher bar, as mentioned previously. Note that we’ve assigned a value of 18px for its width property and a background image "tab_left" tiled vertically, which will make the bar look like a tabbed panel. Once more, feel free to include any image according to your personal taste. Now we’re getting somewhere! The HTML markup is listed below:

     

    <div id="navbar">

    <h1>Navbar Section</h1>

    <p>Content goes here...</p>

    </div>

    <div id="headlines">

    <h1>Headline Section</h1>

    <p>Content goes here...</p>

    </div>

    <div id="content">

    <h1>Page Name</h1>

    <h2>Section title</h2>

    <h3>Article title</h3>

    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec molestie.

    Sed aliquam sem ut arcu. Phasellus sollicitudin. Vestibulum condimentum

    facilisis nulla. In hac habitasse platea dictumst. Nulla nonummy. Cras quis

    libero. Cras venenatis. Aliquam posuere lobortis pede. Nullam fringilla

    urna id leo.Praesent aliquet pretium erat. Praesent non odio.Pellentesque

    a magna a mauris vulputate lacinia. Aenean viverra. Class aptent taciti

    sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos.

    Aliquam lacus. Mauris magna eros, semper a, tempor et, rutrum et, tortor.</p>

    </div>

     

    Well, don’t blame me for being a little verbose about the example. It's just that I was looking for a little inspiration and…couldn’t find it. Okay, let’s take a closer look at the HTML markup. It’s really simple and well structured. As we can see, the left positioned <div> defined as "navbar" is the target element to be displayed and hidden in sequence. Hopefully you’re wondering, how can it be done? The answer is a JavaScript function that will perform the hide-show task, according to the user’s actions. It’s time to code, don’t you agree?

     

    More JavaScript Articles
    More By Alejandro Gervasio


       ·  The approach explained in the article might be a good add-on for sites looking...
       · Sorry about that; we had to do that to get the article to fit properly.
       · Hi Terri,No problem about that :-). Thank you for the aclaration.
       · of using that technique for almost 3 years on my site now (onlinetools.org), but I...
       · Hello friend,Thank you for the comment. Definiltively, setting a cookie for...
       · Yes, how would we be able to call the onclick function from another function? Or am...
       · According to your comnents, I thik the best way to keep user preferences is using a...
     

    JAVASCRIPT ARTICLES

    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps
    - Adding Zoom Controls to Yahoo! Maps
    - Working with Yahoo! Maps
    - Building Image Zooming Controls with the DOM...
    - Working with Multiple Graphics for a Zoom Ap...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway