Home > Web Front-end > JS Tutorial > body text

jquery uses the offset() method to obtain the xy coordinates of the element_jquery

WBOY
Release: 2016-05-16 16:36:53
Original
1488 people have browsed it

To get the absolute X, Y coordinates of an element on the page, you can use the offset() method: (body attribute setting margin: 0; padding: 0;)

var X = $('#DivID').offset().top; 
var Y = $('#DivID').offset().left; 
获取相对(父元素)位置: 
var X = $('#DivID').position().top; 
var Y = $('#DivID').position().left;
Copy after login

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