SoFunction
Updated on 2025-04-03

JavaScript method to get the position coordinates of objects in page

This article describes the method of obtaining the coordinates of the position of objects in the page by JavaScript. Share it for your reference, as follows:

<script language="javascript" type="text/javascript" >
function getXY(Obj) 
{
  var h = ;
  for (var sumTop=0,sumLeft=0;Obj!=;sumTop+=,sumLeft+=, Obj=);
  sumTop = h+sumTop;
  return {left:sumLeft,top:sumTop}
}
</script>

For more information about JavaScript, readers who are interested in reading this site's special topic:Summary of JavaScript mouse operation skills》、《JavaScript object-oriented tutorial"and"Summary of JavaScript data structure and algorithm techniques

I hope this article will be helpful to everyone's JavaScript programming.