The example in this article describes how JavaScript obtains the position coordinates of an object on the page. Share it with everyone 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>
Readers who are interested in more JavaScript-related content can check out the special topics on this site: "Summary of JavaScript mouse operation skills", "Javascript object-oriented introductory tutorial" and "Summary of JavaScript data structure and algorithm skills》
I hope this article will be helpful to everyone in JavaScript programming.