Home > Web Front-end > JS Tutorial > jQuery gets the absolute/relative position of the page element, that is, the absolute X, Y coordinates_jquery

jQuery gets the absolute/relative position of the page element, that is, the absolute X, Y coordinates_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:56:40
Original
1529 people have browsed it

获取页面某一元素的绝对X,Y坐标,可以用offset()方法:

复制代码 代码如下:

var X = $('#DivID').offset().top;
var Y = $('#DivID').offset().left;

获取相对(父元素)位置:
复制代码 代码如下:

var X = $('#DivID').position().top;
var Y = $('#DivID').position().left;
Related labels:
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