15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<br />

<br />

bgColor<br />

Compatibility ✓<br />

Chapter 15 ✦ The NN4 Layer Object (Chapter 31)<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Example<br />

You can have some fun with Listing 31-3, which uses a number of layer scripting<br />

techniques. The page presents a kind of palette of eight colors, each one created as<br />

a small layer (see Figure 15-1). Another, larger layer’s bgColor property changes as<br />

you roll the mouse over any color in the palette.<br />

Figure 15-1: Drag the mouse across the palette to change the<br />

layer’s background color.<br />

To save HTML lines to create those eight color palette layers, I use a script to<br />

establish an array of colors and then document.write() the tags with<br />

appropriate attribute settings so the layers all line up in a contiguous row. By predefining<br />

a number of variable values for the size of the color layers, I can make all of<br />

them larger or smaller with the change of only a few script characters.<br />

The document object handles the job of capturing the mouseOver events. I turn<br />

on the document’s captureEvents() method such that it traps all mouseOver<br />

445<br />

document.layerObject.bgColor

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!