viewable coordinates of an element

S

steven acer

i have an INPUT element inside a scrolling DIV.initially the element's
position is off screen or off the viewable part of it
and has coordinates as follows X=223 Y=2225.
Is there a way to like when i scroll the DIV to this element,
calculate the "viewable" coordinates if the element with respect to
the page.
example: when i scroll to it i would expect a Y (if vertically ) value
<= page height but i always get the offscreen
coordinates
thanks
 
T

Thomas 'PointedEars' Lahn

steven said:
i have an INPUT element inside a scrolling DIV.initially the element's
position is off screen or off the viewable part of it
and has coordinates as follows X=223 Y=2225.
Is there a way to like when i scroll the DIV to this element,
calculate the "viewable" coordinates if the element with respect to
the page.
example: when i scroll to it i would expect a Y (if vertically ) value
<= page height but i always get the offscreen coordinates

You are looking for the scrollLeft and scrollTop properties of the DIV ...
and someone who teaches you how to write text in an easily legible way.

http://jibbering.com/faq/


PointedEars
 
S

steven acer

lol sorry about that flubbed intro ! it's just that i'm really new to
javascript and web design as a whole, i'm just writing a small
online help module for an application i'm currently working on so i
might use the wrong terms sometimes.

anyways, i hope i was able to explain my situation here because what
you're suggesting simply yields
scrollLeft=0 and scrollTop=0 in FF 2.0 and in IE 7.

let me reform just a bit:
here's my code first
<div id="content">
...
<input type="text" id="dec_cod"
onKeyDown="showHelp(event);return(false);"/>
</div>

when the text field is scrolled into view either as a result of a
user's action or via javascript, i want
to calculate the coordinates of the point in the page that sits on the
top left corner of the newely visible text.
i have tried calculating the offsetTop of the element with respect to
the HTML element but it yielded the exact Y coordinate on the page.
dammit i guess this is an even more clunky explanation, anyway thanks
for your time man.
 
S

steven acer

i need the coordinates to display a tool tip div on that text field if
that makes more clear
 
T

Thomas 'PointedEars' Lahn

steven said:
lol sorry about that flubbed intro ! it's just that i'm really new to
javascript and web design as a whole, i'm just writing a small
online help module for an application i'm currently working on so i
might use the wrong terms sometimes.

The issue was and is not your possible (mis)using of terms; I would have
referred to "understandable" then. It is the overall makeup of your
articles (or rather the lack thereof) that makes them hardly *legible*,
and so unlikely to be regarded at all.
anyways, i hope i was able to explain my situation here because what
you're suggesting simply yields
scrollLeft=0 and scrollTop=0 in FF 2.0 and in IE 7.

(Don't include manual newlines in automatically word-wrapped paragraphs.)

At least in Firefox 2.0.0.8 it does not. Probably you are accessing the
wrong element object.
let me reform just a bit:
here's my code first
<div id="content">
..
<input type="text" id="dec_cod"
onKeyDown="showHelp(event);return(false);"/>
</div>

when the text field is scrolled into view either as a result of a
user's action or via javascript, i want
to calculate the coordinates of the point in the page that sits on the
top left corner of the newely visible text.
i have tried calculating the offsetTop of the element with respect to
the HTML element but it yielded the exact Y coordinate on the page.

Try this:

var divContent = document.getElementById("content");
if (divContent)
{
window.alert(divContent.scrollTop);
}
[top post: full quote below the reply]

Please don't do that again. You should read the FAQ, to which I have
pointed you already, about how to post properly.


PointedEars
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top