spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / domscripting / 2 To page 1current pageTo page 3To page 4
[previous][next]
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Scripting for 5th Generation Browsers and Beyond

Object Constructors

Having worked our way through the basic premise of detection routines and if/else statements, let's begin to build our JavaScript object construction routine. The purpose of this section of the script is to convert CSS layers into JavaScript objects that can be easily dynamically manipulated later on in the scripting routine.

function layerObject(id,position,left,top,visibility) {
if (is.ie5|| is.ie55||is.ie6|| is.ns6){
this.obj = document.getElementById(id).style;
this.obj.position = position;
this.obj.left = left;
this.obj.top = top;
this.obj.visibility = visibility;
return this.obj;
}
}

The script is dedicated to creating attributes for JavaScript objects. A good way to think of this is to conceptualize a CSS layer written in the body section of your document. In the definition below, note how the initial positioning is set to 0 and visibility to hidden. Later on we will dynamically position the layer and also toggle its visibility to visible.

<div id="centerLayer" 
     style="position: absolute; width:200px; height:24px; 
            left: 0px; top: 0px; z-index: 6; 
            visibility: hidden;"> </div>

You will notice that in the div tag we have an id attribute. Similarly, in our layer object we also assign an id attribute. The reasoning behind this is that what we are attempting to achieve is a JavaScript replication of the CSS layer attributes. Following this course of logic, we then assign more CSS layer attributes to the layerObject script. We assign, position, top, left and visibility. More attributes could be assigned as needed, for instance we could include z-index, height, width and so on. The object constructor can become very detailed and thus ideally open itself to a myriad of dynamic manipulations. For the purposes of this article, however, let's stick with just a couple of basic attributes to get accustomed to the concepts presented here.

It is important to note that, in reality, our object constructor has not really created anything. All we have done is prepared our documents for the creation of new layer objects. Therefore, we need to focus our attention on actually creating new layer objects. This is achieved with the layerSetup() script.

function layerSetup() {
	centerLyr = new layerObject('centerLayer','absolute', 
                                     page_width/2-100,
                                     page_height/2-12,
                                     'visible');
}

The first line defines the function's name. The second line does quite a few things so let's pull it apart to better understand it.

We create a new variable centerLyr and tell the browser that it equals a new layerObject(). The sole purpose of this section of the JavaScript statement is to hook back into our layerObject() script so that we can then assign the specific values needed for that particular layer. You can identify the attribute value that belongs to the layerObject() properties by looking at the following table.

Function Name ID Property Position Property Left Property Top Property Visibility Property
LayerObject Id Position left top visibility
LayerSetup CenterLayer Absolute page_width/2-100 page_height/2-12 visible

The upshot of this little piece of scripting is that we end up with a new JavaScript object called centerLayer which has the CSS attributes of positioning, left, top, and visibility assigned to it. From a scripting perspective this is enormously useful because if we so wished we could then manipulate any of the CSS properties - as we shall see later on in this article.

Contents:

home / programming / javascript / domscripting / 2 To page 1current pageTo page 3To page 4
[previous][next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle


Created: August 22, 2001
Revised: August 22, 2001


URL: http://webreference.com/programming/javascript/domscripting/2/2.html