Javascript and Style coordinates Question

L

Lars Netzel

I have a little <Div> following the Mousecursor on mousemove event of
page...

refObject.style.top = event.y
refObject.style.left = event.x

It works fine... BUT when there's a lot more on the page (a growing
Datagrid) which make page need to scroll and you scroll down... the
coordinates does not match the mouscursor anymore since the Top value is not
getting as big as it needs from the event.y property

So how do I calculate how much I have to add to the top style value or can I
somehow convert the event.y to the actualy value from the Top of the page?

best Regards/

Lars Netzel
 
C

Chris Botha

Give this a shot:
document.body.scrollTop + event.y;
If you are using flow layout, you may want to try this:
document.body.scrollTop + event.clientY;
 
L

Lars Netzel

Yes, thank you! I did get that tip before you wrote this but it was the
solution that worked. Thank you!

/Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top