JavaScript gets the coordinates of an object's position on the page
- 2020-12-18 01:44:49
- OfStack
This article is an example of how JavaScript gets the coordinates of an object's position on a page. To share for your reference, the details are as follows:
<script language="javascript" type="text/javascript" >
function getXY(Obj)
{
var h = Obj.offsetHeight;
for (var sumTop=0,sumLeft=0;Obj!=document.body;sumTop+=Obj.offsetTop,sumLeft+=Obj.offsetLeft, Obj=Obj.offsetParent);
sumTop = h+sumTop;
return {left:sumLeft,top:sumTop}
}
</script>
For more information about JavaScript, please refer to JavaScript Mouse Operation Skills Summary, javascript Object Oriented Tutorial and JavaScript Data Structure and Algorithm Skills Summary.
I hope this article has been helpful in JavaScript programming.