views:

46

answers:

3

I am getting the screen coords of my mouse click using clientX and clientY in IE. I am using these coords to plot a point on an openlayers map however, the x axis is always perfect but the y axis is always exactly 86 pixels out. At the moment I am just getting round this by doing clientY - 86 but obviously this is no good as a long term solution. Does anyone know what/where this 86 is and how I can access the value on the fly?

A: 

Javascript uses the top-left corner of the screen as base for positioning.

The x-coordinate is calculated by the distance between the left side of the screen and your pointer

the y-coordinate is calculated by the distance between the top side of the screen and your pointer, because the total amount of pixels your favorites bar, address bar, .. occupies is 86 pixels, this result might seem a bit odd

Molske
thanks, do you know how i can calculate the number of pixels taken up by all of these toolbars? Obvioulsy everyones setup is different and i need a consistent xythanks
I don't know if this is possible in a pretty way (i'm not that much of a JS master, all i know is that the mouse positioning in JS is like going trough hell), but the link provided by palindrom seems like a good start.An other solution might be to position the part of the site you want to use these coordinates in at a fixed height from the top of your screen.
Molske
A: 

It seems you are comparing the x/y of mouse in the view area with the actual x/y of the position on screen.

clientX and clientY return the mouse co-ordinates in the viewable browser window, not the users entire screen.

Tom Gullen
A: 

Use the script given at this link.

palindrom