find pos of image

J

Jes

I have an image and on Click I want to display a table with 3 rows
showing options (similar to menu)
I would like to display this table exactly beneath and to the left of
the image.
I am using the following code:

function findPos(elemID) {
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail)
{
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
return { left: offsetLeft, top:eek:ffsetTop };
}

function show_coords(event,layername,imagename)
{
var ff=document.getElementById(imagename);
var hh=ff.height;
var ww=ff.width;
var ff=document.getElementById(layername);
ff.style.top=findPos(imagename).top;
ff.style.left=findPos(imagename).left;
}

The layername is being displayed almost in the middle of the image.
Can someone tell me why please ?
 
J

Jes

No, they (we) can only speculate. There are plenty of reasons for
expecting failure as a result of seeing your code. For example, the
values assigned to the top and left properties of the style object are
not provided with units, and non-zero values require units in CSS. Some
browsers (in some rendering modes) will assume that the absence of units
imply pixel values, some will not (and so disregard the assignments).
Also, the position calculating function is the basic version that only
really works for a subset of elements (usually with implicit or explicit
dispaly:block; styling), all with no borders, no scrolling overflow and
on pages without any margins, borders or padding on the "root" element.

We can't see the mark-up so we don't now the structure this cod is
attempting to interact with or the rendering mode(s) that may b being
used, we can't see the CSS to see how it may impact on the behaviour,
and we don't know which browser(s) exhibit the symptoms you are
describing (which rendering modes they may offer, and which would be
triggered by the mark-up, how they may respond to the invalid CSS
assignments, etc.). Indeed, I can only guess at what "displayed almost
in the middle of the image" means.

Richard.- Hide quoted text -

- Show quoted text -

Thanks for your reply.
 

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
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top