JavaScript
  Home arrow JavaScript arrow Page 2 - Switching on Layers with Scripts
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  
Moblin 
JMSL Numerical Library 
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

Switching on Layers with Scripts
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2004-06-08

    Table of Contents:
  • Switching on Layers with Scripts
  • Starting with a Basic HTML Page
  • VBScript Subroutines
  • Using an Array
  • JavaScript Version

  • 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


    Switching on Layers with Scripts - Starting with a Basic HTML Page


    (Page 2 of 5 )

    The techniques described in this article really work best with graphical elements alongside the code. I won't be showing you how to create those as that's another article in itself; I'll just describe them as best as I can and assume that you have a similar set to work with. The underlying principles are the same, and the script will work just as well with pure text. Let's make a start on the coding.

    Get yourself a basic HTML page set up with the usual tags:

    <html>
    <head>
    <title>Using Layers</title>
    </head>
    <body>
    </body>
    </html>

    Now define the basic page layout. We make extensive use of the <div> tag. The tag is extremely useful for grouping page elements into logical blocks, or divisions. Each of these divisions are named and can thus be manipulated with scripting. Make a note also of the z-index property of the <style> tag; this is how you define layers in web pages. The z-index gives your web pages a third dimension to work with. Any object, such as a picture or paragraph of text with a z-index of say 3 will appear above an object with a lower z-index, but below an object with a higher z-index. 

    As stated above, I'm assuming that you have some graphics to use for this task. I've used a collection of pictures to give the effect of a folder with tabs along the top. The main body of the folder is the background image, with the separate tabs along the top. Another point to note is the left and top positioning properties; using the exact pixel locations I have suggested below may result in the picture appearing differently if your screen resolution is set differently. This is obviously an issue that you will need to address when using the code online but is adequate for the purpose of this article.

    Add the following code in between the <body> tags:

    <h1>Understanding Layers</h1>
    <hr>
    <br><br>
    <div id=tab1 style="position:absolute;left:16;top:116;z-index:3">
    <img src="tab1.gif">
    </div>
    <div id=tab2 style="position:absolute;left:95;top:115;z-index:2">
    <img src="tab2.gif">
    </div>
    <div id=tab3 style="position:absolute;left:185;top:114;z-index:1">
    <img src="tab3.gif">
    </div>
    <div id=tab4 style="position:absolute;left:276;top:116;z-index:0">
    <img src="tab4.gif">
    </div>
    <div id=background style="position:absolute;top:150;z-index:-1">
    <img src="background.gif">
    </div>
    <div id=startmessage style="position:absolute;top:250;left:100;z-index:-1">
    Welcome to the easy content manager. <br>Pick a tab to display information
    </div>
    <div id=content1 style="position:absolute;top:200;left:50;z-index:4;">
    Test content<br>test content
    </div>
    <div id=content2 style="position:absolute;top:200;left:50;z-index:4;">
    Test content 2<br>test content 2
    </div>
    <div id=content3 style="position:absolute;top:200;left:50;z-index:4;">
    Test content 3<br>test content 3
    </div>
    <div id=content4 style="position:absolute;top:200;left:50;z-index:4;">
    Test content 4<br>test content 4
    </div>

    This will form almost the entirety of your page, but it will change when you are using actual content instead of test content. The remainder of the code is placed within the <head> tag. First, define your scripting language. I'll show you the VBScript way, so add the following:

    <script language="VBScript">
    <!- - stealth mode on

    The comment indicator is used to wrap up the script so that older browsers, which don't support scripting, simply ignore it.  You don't have to add 'stealth mode on' after the comment wrapper, you could simply add 'cloaking', 'invisibility', or anything you want.  It's a comment at the end of the day.

    More JavaScript Articles
    More By Dan Wellman


     

    JAVASCRIPT ARTICLES

    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - 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






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT