15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

esizeBy(deltaX,deltaY)<br />

resizeTo(width,height)<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 />

It is important to understand the ramifications of content flow when these two<br />

methods resize a layer. Listing 31-12a (and the companion document Listing 31-12b)<br />

shows you how to set the lower-right corner of a layer to be dragged by a user for<br />

resizing the layer (much like grabbing the resize corner of a document window).<br />

Three radio buttons enable you to choose whether and when the content should be<br />

redrawn to the layer — never, after resizing, or during resizing.<br />

Event capture is very much like that in Listing 31-11 for layer dragging. The primary<br />

difference is that drag mode is engaged only when the mouse event takes<br />

place in the region of the lower-right corner. A different kind of offset value is saved<br />

here because, for resizing, the script needs to know the mouse event offset from the<br />

right and bottom edges of the layer.<br />

Condition statements in the resizeIt() and release() functions verify<br />

whether a specific radio button is checked to determine when (or if) the content<br />

should be redrawn. I designed this page with the knowledge that its content might<br />

be redrawn. Therefore, I built the content of the layer as a separate HTML document<br />

that loads in the tag.<br />

Redrawing the content requires reloading the document into the layer. I use the<br />

layerObject.load() method because I want to send the current<br />

layerObject.clip.width as a parameter for the width of the clip region to<br />

accommodate the content as it loads.<br />

An important point to know about reloading content into a layer is that all property<br />

settings for the layer’s event capture are erased when the document loads.<br />

Overcoming this behavior requires setting the layer’s onLoad event handler to set<br />

the layer’s event capture mechanism. If the layer event capturing is specified as part<br />

of the statements at the end of the document, the layer ignores some important<br />

events needed for the dynamic resizing after the document reloads the first time.<br />

As you experiment with the different ways to resize and redraw, you see that<br />

redrawing during resizing is a slow process because of the repetitive loading (from<br />

cache) needed each time. On slower client machines, it is easy for the cursor to<br />

outrun the layer region, causing the layer to not get mouseOver events at all. It may<br />

not be the best-looking solution, but I prefer to redraw after resizing the layer.<br />

Listing 31-22 in the <strong>JavaScript</strong> <strong>Bible</strong> shows a version designed for the IE5+ and<br />

NN6 object models. Because content automatically reflows in those browsers,<br />

you do not have to load the content of the positioned element from an external<br />

document.<br />

465<br />

document.layerObject.resizeBy()

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

Saved successfully!

Ooh no, something went wrong!