javascript 元素在畫面上,無論視窗大小,相對位置都不會改變

設定元素位置

<!DOCTYP html>
<html>
<head>
<meta charset="UTF-8" >
<script>

</script>
<
<script>
function position()
{
  var x = pic.offsetLeft;
  var y = pic.offsetTop;
 
 document.getElementById("pic2").style.position = "absolute";
  document.getElementById("pic2").style.left = ( x + 150 );
  document.getElementById("pic2").style.top = ( y + 150) ; ;
   
    console.log(pic2.offsetLeft + "," + pic2.offsetTop);
  
}

</script>
</head>
<body onresize="position()" onload="position()">


<table width="100%" border="1">
<tr><td width="50%">&nbsp;</td><td width="50%">&nbsp;</td></tr>
</table>
      <img src="c:\Chrysanthemum.jpg" id="pic" width="300" height="300"  style="position:absolute;margin-left:50%;z-index:5;min-width:300px;min-height:300px;" >
      
      <img src="c:\Penguins.jpg" width="10" height="10" id="pic2" style="z-index:5;"   />
      </img>


</body>
</html>