By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,451 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,451 IT Pros & Developers. It's quick & easy.

current coordinates of an element

P: 35
is there a way in javascript to retrieve the current coordinates of an element on screen with respect to the page viewport as well as the screen.?
i'm having this case where i have an INPUT element inside a DIV element and i have to scroll vertically through the DIV to view it.I want to get its coordinates when it is visible on the screen (ie. the coordinates that typically make it visible)
before scroll
x=232
y=2225

after scroll
x=232
y=384 // should be but it's always 2225.

i'm stuck on something else, what would i do to retrieve the coordinates of a KeyEvent?
Oct 26 '07 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
hi ...

you may use the onscroll-event to observe the event - add that handler ... with that you may normalize the coordinates to your viewport. for that you may use the pageXOffset, pageYOffset and/or srcollLeft, scrollTop coordinates in IE ... so the scrolling moves the viewport and you may write a function that computes the visibility when the current scroll-position makes your element visible ...

kind regards
Oct 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.