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
Release: 2016-05-16 15:16:15
Original
1497 people have browsed it

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>

Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template