Home >Web Front-end >JS Tutorial >JavaScript method to obtain the position coordinates of an object in the page_javascript skills

JavaScript method to obtain the position coordinates of an object in the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:16:151517browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn