Reputation: 8977
Is there a way to find the y content offset from a javascript. The definition of content offset is:
The point at which the origin of the content view is offset from the origin of the scroll view
Upvotes: 0
Views: 1652
Reputation: 66693
You can use the below code to find the position:
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return curtop;
}
You can call it like findPos(document.getElementById('myID'));
Check this URL for explanation: http://txt.binnyva.com/2007/06/find-elements-position-using-javascript/
Upvotes: 2
Reputation: 8871
Use offsetLeft
and offsetTop
to know the X and Y co-ord of an element.
var X=element.offsetLeft;
var Y=element.offsetTop
for more help : https://developer.mozilla.org/en/DOM/element.offsetLeft
Upvotes: 1