Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > element position inside scrollable div tag

Reply
Thread Tools

element position inside scrollable div tag

 
 
unixfreak compiler
Guest
Posts: n/a
 
      02-17-2006
I'm using the algorithm listed beow to get the position of an element.
Some elements are located inside DIV tags that can scroll. The
scrolling doesn't seem to change the X and Y coordinates I get back
from this algorithm so it ends up being wrong.

What do I need to do to include the effects of the scroll bar?

- john

function getElementPosition(elementID) {

var element = document.getElementById(elementID);
if (element == null) { return null; }
var xPos = findPosX(element);
var yPos = findPosY(element);

return { x : xPos, y : yPos };
}

function findPosX(obj) {

var curleft = 0;

if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
} else if (obj.x) {
curleft += obj.x;
}

return curleft;
}

function findPosY(obj) {

var curtop = 0;

if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop
obj = obj.offsetParent;
}
} else if (obj.y) {
curtop += obj.y;
}

return curtop;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Position fixed and scrollable DIV Marcus HTML 0 10-06-2008 10:11 AM
How Can I Find Mouse Position Inside of a Div Tag? vunet.us@gmail.com Javascript 4 01-06-2007 05:23 AM
Select text within a div tag by clicking on content of div tag or a button? visu Javascript 4 11-22-2006 06:25 AM
Select text within a div tag by clicking on content of div tag? M Wells Javascript 0 10-06-2004 11:04 AM
Setting Scrollable position for div tag Muralidhar Javascript 0 09-01-2003 11:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57