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 
Moblin 
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 II
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2005-03-28

    Table of Contents:
  • Controllable Navigation Bars with JavaScript, Part II
  • Dealing with those details
  • Cleaning up the CSS styles
  • JavaScript to the rescue: the improved "switchBar()" function

  • 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 II - Dealing with those details


    (Page 2 of 4 )

    In the first article, we developed a simple JavaScript function that works in conjunction with some CSS styles, and performs fairly decently the task of hiding and showing a side bar within a Web document. Let's remind ourselves how the function looked originally:

    <script language="javascript">

    switchBar=function(){

    var navbar,content,swbar;

    navbar=document.getElementById('navbar');

    if(!navbar){return;}

    content=document.getElementById('content');

    if(!content){return;}

    swbar=document.createElement('div');

    swbar.id='switchbar';

    swbar.title='hide navbar';

    content.parentNode.insertBefore(swbar,content);

    swbar.onclick=function(){

    if(navbar.style&&swbar.style){

    if(!navbar.style.display||navbar.style.display=='block'){

    navbar.style.display='none';

    swbar.style.backgroundImage='url(tab_right.gif)';

    swbar.title='show navbar';

    }

    else{

    navbar.style.display='block';

    swbar.style.backgroundImage='url(tab_left.gif)';

    swbar.title='hide navbar';

    }

    }

    }

    }

    window.onload=function(){

    if(document.getElementById&&document.createElement){

    switchBar();

    }

    }

    </script>

    To work in conjunction with the above function, we had basically defined three contextual selectors to be applied to the main containing <div> elements and one additional for the switcher bar:

    <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>

    However, the primitive function was set up to work with fixed-height <div> elements, certainly something that I'd prefer to stay away from, at least for liquid design. Another important drawback is that we were using a value of "auto" for setting the width attribute for the main <div> container or "content" column, in order to make it expand and collapse in turn.

    But here, we're stepping on the wet floor of browser incompatibilities. Is that pretty familiar to you? Yes, some browsers don't behave in the same manner when they have to interpret this value, which keeps it from being more widely used. So, we're going to tackle all of these odd points present in the original script and CSS declarations, and try to fix  the buggy features, in order to gain functionality and make the whole code more compatible with most browsers. Are you ready to face the challenge? It's not so difficult.

    More JavaScript Articles
    More By Alejandro Gervasio


       · Over this second part, the article deals with some browser incompatibilitiesand...
     

    JAVASCRIPT ARTICLES

    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - 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







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