offsetLeft
and other one is offsetTop
. document.getElementById('i1').offsetLeft;
document.getElementById('i1').offsetTop;
In the above code i1 is the id of the image. Read more on Image object and its properties
<img src=top2.jpg id=i1>
Demo of Image offset
<html>
<head>
<title>Demo of Image offset in JavaScript</title>
<script language='JavaScript' type='text/JavaScript'>
<!--
function disp_img(str) {
var x=document.getElementById('i1').offsetLeft;
var y=document.getElementById('i1').offsetTop;
document.getElementById("msg").innerHTML="X: " + x + " Y : " + y
}
//-->
</script>
</head>
<body >
<img src=images/help.jpg id='i1' style="position:absolute; left: 500; top: 100;">
<br><br><input type=button onClick=disp_img() value='Show Details'>
<div id='msg'></div>
</body>
</html>
krati jain | 24-10-2014 |
I feel this is a good effort krati jain |
vitthal chandane | 09-04-2015 |
i fill that it is nice solution which i help to solve my problem. |