473,503 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining position

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
6 1167
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
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
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

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1341
by: D & J Gilchrist | last post by:
Hi Is there any way of determining the width and height of a graphic in pixels (.jpg) and reporting this? Also, maybe following the above, can a picture-box position be automatically moved to...
25
1830
by: Sean Berry | last post by:
Say I have a dictionary like the following {1:'one',2:'two',4:'three',8:'four',16:'five', etc...} and I am given some numbers, say 22, 25, and 9. I want to determine the keys, powers of 2,...
3
1241
by: CES | last post by:
All, Is their a way of finding the position of the browsers top-left-hand-corner as it relates to the monitors screen resolution?? By that I mean that if the browser's window is at the upper most...
35
5128
by: Dr.Tube | last post by:
Hi there, I have this web site (www.DrTube.com) which has the following DTD: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> which switches...
1
2884
by: Steve Edwards | last post by:
I have a form with a list box, and the items selected from that list box are used to add values to the WHERE clause of a query that is the data source for a report. For each item chosen from the...
2
7545
by: Ryan | last post by:
Access97 I hope someone out there can help. This is driving me crazy. Basically, I am trying to recreate VBA's built in navigation feature (The one that allows you to move first, next,...
10
3706
by: Lyn | last post by:
I have a form set to Single Form mode with which I can cycle through the records in a table via Next and Previous buttons. To avoid users pressing the Previous button on the first record and the...
7
2375
by: todholt | last post by:
Hello, I am trying to bypass a form's automatic update, and instead call a stored procedure in sql server. I am using continuous forms. The problem I am having is with returning to the next...
14
2728
by: googler | last post by:
Is there any C library function that returns the size of a given file? Otherwise, is there a way in which file size can be determined in a C program? I need to get this for both Linux and Windows...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.