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.

444<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

background<br />

Compatibility ✓<br />

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

Example<br />

A simple example (Listing 31-2) defines one layer that features five buttons to<br />

change the background image of a second layer. I put the buttons in a layer because<br />

I want to make sure the buttons and background layer rectangles align themselves<br />

along their top edges on all platforms.<br />

As the second layer loads, I merely assign a gray background color to it and<br />

write some reverse (white) text. Most of the images are of the small variety that<br />

repeat in the layer. One is a large photograph to demonstrate how images are<br />

clipped to the layer’s rectangle. Along the way, I hope you also heed the lesson of<br />

readability demonstrated by the difficulty of reading text on a wild-looking background.<br />

For an example compatible with IE5+ and NN6+, see Listing 31-13.<br />

Listing 31-2: Setting Layer Backgrounds<br />

<br />

<br />

<br />

function setBg(URL) {<br />

document.bgExpo.background.src = URL<br />

}<br />

<br />

<br />

<br />

Layer Backgrounds<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Some text, which may or may not read well with the<br />

various backgrounds.<br />

document.layerObject.background

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

Saved successfully!

Ooh no, something went wrong!