Günter Laudenklos: Position eines Bildes ermitteln (X / Y-Koordinaten)

Beitrag lesen

Hallo Jochen,

sollte so gehen:

<html>
<head>
<script type="text/javascript">
var xx = 0, yy = 0;

function GetPos(lyr,lid)
{
 if(document.layers)
 {
  xx = document.images[lyr].x;
  yy = document.images[lyr].y;
 }
 else
 {
  obj = (document.all) ? document.all.item(lid) : document.getElementById(lid);
  while(obj)
  {
   xx += obj.offsetLeft;
   yy += obj.offsetTop;
   obj = obj.offsetParent;
  }
 }
 alert(xx+' '+yy);
}
</script>
<body onload="GetPos('bname','bid');">

<div align=center>
<img id="bid" name="bname" src="xxx.jpg" width=200 height=300 alt="">
</div>

</body></html>

viele Grüße Günter