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

Determining position

P: n/a
I have some floating divs on my page.

When I click the div I want do display a menu over it, how can I
determine the position of the clicked div on the page?

Sep 9 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
http://www.quirksmode.org/dom/getstyles.html
You are probably looking for the top and left style values.

Let_Me_Be wrote:
I have some floating divs on my page.

When I click the div I want do display a menu over it, how can I
determine the position of the clicked div on the page?
Sep 9 '06 #2

P: n/a
Let_Me_Be wrote:
I have some floating divs on my page.

When I click the div I want do display a menu over it, how can I
determine the position of the clicked div on the page?
Richard Cornford wrote about the difficulty in doing this in general

<URL:
http://groups.google.com/group/comp.lang.javascript/msg/c46e8ec2f5fe4db3?>

Richard, if you happen to be reading, is there a chance you could post
a few of the more basic positioning moduals you have written. Or
perhaps you have a link to one of your pages which uses them?

Thank you,
Peter

Sep 9 '06 #3

P: n/a
try this:
function posMenu(menu, menuBase) {
var offsetObj;
var offsetX, offsetY = 0;
offsetObj = menuBase;
while (offsetObj) {
offsetX += offsetObj.offsetTop;
offsetY += offsetObj.offsetLeft;
offsetObj = offsetObj.offsetParent;
}
menu.style.position = "absulote";
menu.style.top = offsetX + "px";
menu.style.left = offsetY + "px";
}
Let_Me_Be wrote:
I have some floating divs on my page.

When I click the div I want do display a menu over it, how can I
determine the position of the clicked div on the page?
Sep 9 '06 #4

P: n/a

Benjamin wrote:
try this:
function posMenu(menu, menuBase) {
var offsetObj;
var offsetX, offsetY = 0;
should be this?
var offsetX = 0, offsetY = 0;
offsetObj = menuBase;
while (offsetObj) {
offsetX += offsetObj.offsetTop;
offsetY += offsetObj.offsetLeft;
offsetObj = offsetObj.offsetParent;
}
menu.style.position = "absulote";
Should be "absolute"
menu.style.top = offsetX + "px";
menu.style.left = offsetY + "px";
}
I haven't written a positioning function more advanced then the one you
have shown but looking at the Yahoo! UI position function it looks like
the proposed function will only work in a limited set of simple cases
(ie. no frames etc).

Peter

Sep 9 '06 #5

P: n/a
It is true that it will only work in simple cases (if that's simple),
but I assumed that is what he wanted.
pe**********@gmail.com wrote:
Benjamin wrote:
try this:
function posMenu(menu, menuBase) {
var offsetObj;
var offsetX, offsetY = 0;

should be this?
var offsetX = 0, offsetY = 0;
offsetObj = menuBase;
while (offsetObj) {
offsetX += offsetObj.offsetTop;
offsetY += offsetObj.offsetLeft;
offsetObj = offsetObj.offsetParent;
}
menu.style.position = "absulote";

Should be "absolute"
menu.style.top = offsetX + "px";
menu.style.left = offsetY + "px";
}

I haven't written a positioning function more advanced then the one you
have shown but looking at the Yahoo! UI position function it looks like
the proposed function will only work in a limited set of simple cases
(ie. no frames etc).

Peter
Sep 10 '06 #6

P: n/a

pe**********@gmail.com wrote:
Benjamin wrote:
try this:
function posMenu(menu, menuBase) {
var offsetObj;
var offsetX, offsetY = 0;

should be this?
var offsetX = 0, offsetY = 0;
offsetObj = menuBase;
while (offsetObj) {
offsetX += offsetObj.offsetTop;
offsetY += offsetObj.offsetLeft;
offsetObj = offsetObj.offsetParent;
}
menu.style.position = "absulote";

Should be "absolute"
menu.style.top = offsetX + "px";
menu.style.left = offsetY + "px";
}

I haven't written a positioning function more advanced then the one you
have shown but looking at the Yahoo! UI position function it looks like
the proposed function will only work in a limited set of simple cases
(ie. no frames etc).
Matt Kruse has a reasonable effort as part of his JavaScript toolkit:

<URL: http://www.javascripttoolbox.com/lib/objectposition/ >
There is a simpler version at Quirksmode:

<URL: http://www.quirksmode.org/js/findpos.html >
--
Rob

Sep 10 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.