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.

416<br />

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

Finally, if you are a Windows user, here are two examples to try to see some of<br />

the unexpected behavior of coordinate properties.<br />

1. With the page not scrolled, click anywhere along the right side of the page,<br />

away from any text so that the BODY element is srcElement. Because the<br />

BODY element theoretically fills the entire content region of the browser window,<br />

all coordinate pairs except for the screen coordinates should be the<br />

same. But offset properties are two pixels less than all the others. By and<br />

large, this difference won’t matter in your scripts, but you should be aware of<br />

this potential discrepancy if precise positioning is important. For inexplicable<br />

reasons, the offset properties are measured in a space that is inset two pixels<br />

from the left and top of the window. This is not the case in the Macintosh version,<br />

where all value pairs are the same from the BODY perspective.<br />

2. Click the text of the H1 or P elements (just above and below the long horizontal<br />

rule at the top of the page). In theory, the offset properties should be relative<br />

to the rectangles occupied by these elements (they’re block elements,<br />

after all). But instead, they’re measured in the same space as the client properties<br />

(plus the two pixels). This unexpected behavior doesn’t have anything<br />

to do with the cursor being a text cursor, because if you click inside any of the<br />

text box elements, their offset properties are properly relative to their own<br />

rectangles. This problem does not afflict the Macintosh version.<br />

You can see further examples of important event coordinate properties in action<br />

in the discussion of dragging elements around the IE page in Chapter 31 of the<br />

<strong>JavaScript</strong> <strong>Bible</strong>.<br />

fromElement<br />

toElement<br />

(IE) event.fromElement<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

Listing 29-15 provides an example of how the fromElement and toElement<br />

properties can reveal the life of the cursor action before and after it rolls into an<br />

element. When you roll the cursor to the center box (a table cell), its onMouseOver<br />

event handler displays the text from the table cell from which the cursor arrived. In<br />

Figure 13-1, for example, the user has just rolled the cursor into the center box from<br />

the West box. If the cursor comes in from one of the corners (not easy to do), a different<br />

message is displayed.

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

Saved successfully!

Ooh no, something went wrong!