Table with div submenu

H

HDI

Hi,

I've got a table and when a user moves over a row I want to show a div
with a submenu.

The code is ok but when I move over a row he sets the top and left to
the mousepoitners top and left (event.clientX and event.clientY).

How can I put the div(submenu) to the top of the row and the right
side.

Thx
 
L

Leandro Ardissone

Hi,

You can use those functions to find the position X and Y on most
browsers of an element:
function findPosX(obj) {
var curleft = 0;
if(obj.offsetParent)
while(1)
{
curleft += obj.offsetLeft;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj) {
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
}


obj is the row of the table in your case, and do a simple calculation
to get the most right part of the row.


cheers..
 
H

HDI

Leandro Ardissone schreef:
Hi,

You can use those functions to find the position X and Y on most
browsers of an element:
function findPosX(obj) {
var curleft = 0;
if(obj.offsetParent)
while(1)
{
curleft += obj.offsetLeft;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj) {
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
}


obj is the row of the table in your case, and do a simple calculation
to get the most right part of the row.


cheers..


How do I pass that row?

Y = findPosY(???)
 
L

Leandro Ardissone

HDI said:
Leandro Ardissone schreef:



How do I pass that row?

Y = findPosY(???)


The argument of findPosY is the parent item..

something like:
Y = findPosY(document.getElementById('row').firstChild());
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top