Archive for February, 2008

Shared web hosting - 896 Part III . Document Objects Reference Listing

Wednesday, February 20th, 2008

896 Part III . Document Objects Reference Listing 31-21 (continued) if (targElem.className == draggable ) { while (targElem.id != myLayer && targElem.parentNode) { targElem = targElem.parentNode } if (engaged && targElem.id == myLayer ) { engaged = false } } }

Dragging a Layer


Drag me around the window. The final listing in this section applies many example components used thus far to let scripts control the resizing of a positionable element by dragging the lower- right, 20-pixel region. A lot of the hairy code in the engage()function is for determining if the onmousedown event occurs in the invisible 20-pixel square. The resizeIt() function of Listing 31-22 resembles the dragIt()function of Listing 31-21, but the adjustments are made to the width and height of the position- able element. A fair amount of math determines the width of the element in response to the cursor s instantaneous location and sets the style.widthand style.height properties accordingly. A user s success with resizing an element this way depends a lot on the browser he or she uses. IE, particularly for Windows, may not redraw the resized element very quickly. In this case, the cursor can easily slip out of the hot spot to end the drag. In other browsers, however, response is very fast, and it s very difficult to have the onmouseout event fire the release() function. Listing 31-22: Resizing a Layer (W3C) Layer Resizing