DynLayer Extensions [Common]

These are commonly used additions that you may want to use.

When you want to use these functions you must include both the dynlayer.js and dynlayer-common.js files:

<SCRIPT LANGUAGE="JavaScript" SRC="dynlayer.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="dynlayer-common.js"></SCRIPT>

Download: dynlayer-common.js
View Source: dynlayer-common.js

External File Load - load()

This method is based on the External Source Files lesson.

Usage of the load() method:

mylayer.load = DynLayerLoad
mylayer.load('myfile.html')  

The fn parameter is optional, it's used to execute some other function or statment when the external file has been fully loaded into the page.

In the main HTML document you must have an hidden IFrame named "bufferFrame", this is used to copy the contents of the external file into the layer.

<IFRAME STYLE="display:none" NAME="bufferFrame"></IFRAME>

The external html file must call the DynLayer's loadFinish() method. Since in IE, the main document is in a different frame, we must call it as "parent". Fortunately this is simultaneously compatible for Netscape because in Netscape it is all the same document, and therefore in that case "parent" is synonymous with "document".

<BODY onLoad="parent.mylayer.loadFinish()">

Warnings: This method will not work "as-is" if these these files are all to be contained within another frameset. In that case you'd need to send an additional parameter for the name of the frame instead of "parent". Nor will this work if you want to load multiple files simultaneously into separate layers. This function assumes there's only one IFrame, and hence only one file in a buffer-zone. If you wanted multiple files to be buffered like this you'd have to have separate IFrames, and yet another parameter to determine which frame to take the contents from.

View a load() method Example

Background Color - setbg()

Simply sets the background color of the layer. Watch out though, you usually have to have the layer clipped, and you'll sometimes run into problems with text that's contained within the layer. I'll leave you to encounter all the "fun" with this function :)

Usage of the setbg() Method:

mylayer.setbg = DynLayerSetbg
mylayer.setbg('#ff0000')

Change Image - img()

This one-line method can be used instead of the changeImage() function so that you don't have to worry about nested references:

Usage of the img() Method:

myImgObject = new Image()
myImgObject.src = 'myimg-new.gif'

// define mylayer either manually or by DynLayerInit()
mylayer.img = DynLayerImg
mylayer.img('myImg','myImgObject')

// image must have a name assigned, index values won't work between bother browsers
<div id="mylayerDiv"><img src="myimg.gif" name="myImg"></div>

DynLayer Extensions:

Home Next Lesson: Geometric Objects
copyright 1998 Dan Steinman


Casa de Bender