OK... First...Navigator and Internet Explorer both use the width and height properties to extract the element's width and height. However, they utilize different properties to determine the element's coordinates. Navigator uses x and y to retrieve these values, while Internet Explorer uses offsetLeft and offsetTop to do so.
A better way to define the image's position and dimensions is to first assign the image's reference to a variable.
IE and NS6 differ on what constitutes a container. However, the container is THE PARENT...in the case of a table the parent is the table.
For obtaining an absolute offset, a simple recursive algorithm which walks up the parents and adds up all the offsets will work in both:
<!-- This works for all browser types if using SHTML --> function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); } function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); } function getAbsPos(elt,which) { iPos = 0; while (elt != null) { iPos += elt["offset" + which]; elt = elt.offsetParent; } return iPos; }
This would work with IE (just copy paste) and you could modify it to use variables for IE and NS
var trueOffsetLeft = 0; var trueOffsetTop = 0; var parentObject = document.all['bob']; while (parentObject != null){ trueOffsetLeft += parentObject.offsetLeft; trueOffsetTop += parentObject.offsetTop; parentObject = parentObject.offsetParent; }
-- den går så mange trin op, som der stadig er objekter !-)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.