Joachim: offsetParent - Probleme mit Positionierungen

Beitrag lesen

Hi,

ich weiss leider nicht wie ich mit deinem lösungsansatz da weitermachen könnte...

hm, grade noch mal getestet, offsetTop/Left geht auch bei Positionierung, zumindestens im FF, IE habe ich am Mac jetzt nicht... Schau doch mal das Script mit einem Mix aus relativer und absoluter Positionierung an, vielleicht hülfts,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<style type="text/css">
    body {
        margin: 0;
    }
    div {
        margin: 100px;
        border: 1px solid red;
    }
    p {
        position: absolute;
        top: 150px;
        left: 150px;
        border: 1px solid green;
    }
</style>
<script type="text/javascript">

function findPos(el) {

var xPos = 0;
        var yPos = 0;

while(el) {
            xPos += el.offsetLeft;
            yPos += el.offsetTop;
            el   =  el.offsetParent;
        }
        return {xPos: xPos, yPos: yPos};
    }

function get_pos() {
        var p   =  document.getElementsByTagName("p")[0];
        alert ("x: " +findPos(p).xPos + ", y: " + findPos(p).yPos);
    }
</script>
</head>
<body onload="get_pos()">
    <div>
        <div style="position:relative">
            <p>x</p>
        </div>
    </div>
</body>
</html>

Gruesse, Joachim

--
Am Ende wird alles gut.