12 December, 2005

the layerX property in Firefox

When an element is clicked, you can get the mouse relative coordinates from the top left edge of the element with the e.layerX and e.layerY properties in Firefox. I discovered that the Firefox team made a change from version 1.0 to 1.5. In Firefox 1.0, if your mouse is over the very first top-left pixel of the element (including the border if existing), these properties indicates (0,0) as Safari 1.3 does. But in Firefox 1.5, these are (1,1) ! And you know what, I like the second way better. Because if your element is 200px width, you get layerX from 1px to 200px instead of 0px to 199px as if it was an array index.
On IE, it's very different because the equivalent which is event.offsetX gives you the number of pixel from the left border excluding the border! So that you can get a negative value if your element is bordered. And from the first inside pixel, it works like Firefox 1.0, giving you a 0.
This time, I would give the vote for Firefox 1.5 which convince me the best.

1 comment:

precision machinist said...

Very interesting reading. Thanks.

Sincerely,

Pat
precision machinist