The Dynamic Layer Object API
The Dynamic Layer Object API (DynLayer) is a lightweight object (weighing in at 6 KB) that provides a highly flexible manner of working with layers. Not only does it have common properties and methods for manipulating layers, it is an object based API which opens up a new way of working with layers that far exceeds the traditional way of coding DHTML. I've found it to be the ideal foundation for nearly every application of DHTML including animation, applications, and gaming environments.
I've left the object open-ended, so you can easily customize it to your needs. You can add more methods or properties onto it, or remove whatever parts you feel you won't need. Many of the next lessons in this tutorial will use the DynLayer as the basis for accomplishing some other task, so it is important that you understand how it works and how to use it.
Features of the DynLayer Object:
- an object-based API that is easy to implement as use
- targets in a similar manner that I've used pointers to target layers - to avoid the problems of the different object models between Netscape and IE
- provides it's own properties and methods for changing the location of the layer - to avoid the position problems associated with Microsoft's proprietory way of changing the location
- has the handy hide() and show() methods to change the visibility
- exposes a common event model for layer-based events
- has built-in slide, clip, and write methods
- a css() function to auto-generate CSS syntax
- easy to make additional methods such as wipe, glide, background color, external source files etc.
Revisions:
- I added a "test" function which first double checks to make sure the layers exist before defining the DynLayer. This is perhaps something I should have added a while ago, because it helps a lot when defining DynLayers that are nested multiple times, or are part of a DHTML object. If there's an error it'll show an alert of which layer in the nested hierarchy caused the problem.
- I implemented an IFrame parameter so that the DynLayer can be applied to a layer inside an IFrame in the document. Currently the only situtation in this tutorial where this is used is in the Scroll Object.
- I eliminated the DynLayerAddon() method and just stuck those commands into the constructor. I originally had done this to plan ahead for other features but really it's just redundant and I think few people actually cared about this, myself included.
- I added the write() method and css() function to the DynLayer used in this tutorial because I seem to be using them quite frequently. You can of course remove those or any other part of you don't need to make the file size smaller.
- new "onSlide" handlers have been inserted into the Slide Methods as an alternative way to make sequences and to make the Slide Methods more useful
- Each of these changes are totally backward compatible so you won't need to change any existing code in order to use this updated dynlayer.js.
The Dynamic Layer Object API
Extending the DynLayer
copyright 1998 Dan Steinman