spacer

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

home / experts / dhtml / column10
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
Logo

The DHTML Lab Jigsaw Puzzle, Part III: NN4
creating the puzzle pieces


When the puzzle displays, we begin play by pressing the Break button which calls the breakUp() function. If the puzzle is a new puzzle, createPuzzle() is called. If createPuzzle() realizes that a new piece count is called for, it calls createPieces(). The logic of this flow has been discussed in detail in Part II.

The createPieces() function reads as its previous IE incarnation. It calculates how many pieces are necessary; if the ones already created are not enough, it creates some more; it stores the amount of pieces created so far and assigns the final piece created (the topmost in z-order) to activeEl, so we can track it.

The new Layer Constructor

A first for these columns is the use of Navigator's new Layer constructor to create a new positioned element on-the-fly. The complete syntax is:

This element (layer) will be created, added to the document.layers array, and any HTML written to it will wrap at the width value. This type of element creation can be used only after a page has fully loaded and displayed. It cannot be used in a script outside of a function as, say, new Array can.

Once we have created the element, we can assign values to its various properties to position it, clip it, write to it and so on. The one property that will be missing that all other elements have is ID. We cannot assign an ID value, but Navigator does supply one of its own internally, in the form: _js_layer_layerNumber. The more on-the-fly elements you create, the greater the layerNumber. This incrementation persists throughout a browser session. It does not reinitialize with every page load. So using this internal ID as an identifier is worthless. We will always use the variables we assigned the constructor to. In our example, these are PIECE1, PIECE2...etc. Just for your reference, the first elements created with the constructor would have internal IDs of _js_layer_1, _js_layer_2, etc.

Filling the Pieces

The major difference in createPuzzle() for Navigator is that every puzzle piece has HTML written to it that loads a new image. Our other alternative is to change the src property of the piece elements. This however invokes the deadly "wysiwyg" problem, on reloads. The less said about that, the better.

Therefore, createPuzzle() first establishes the width and height of the pieces to be displayed. It then goes through the puzzle, one row at a time, loading each piece element with an image, and clips it accordingly. It assigns the left and top clip values to each element's clipLeft and clipTop properties (for drag & drop use later).

If grid use is turned on, setGrid() is called, and then the appropriate values are assigned to our variables. When createPuzzle() exits, control is returned to the breakUp() function that disperses the pieces.


Produced by Peter Belesis and

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

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

All Rights Reserved. Legal Notices.
Created: Nov. 27, 1997
Revised: Jan. 18, 1998

URL: http://www.webreference.com/dhtml/column10/puzzNScreate.html