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

jquery method to get the absolute position and relative position of html elements_jquery

WBOY
Release: 2016-05-16 16:43:50
Original
1450 people have browsed it

Absolute position coordinates:

Copy code The code is as follows:

$("#elem").offset().top
$("#elem").offset().left

Position coordinates relative to the parent element:

Copy code The code is as follows:

$("#elem").position().top
$("#elem").position().left

Also:
static (default): default positioning method.
Relative (relative positioning): Based on static, the original position change of the relative element is achieved by setting top, bottom, left, and right.
Absolute (absolute positioning): It is relative to the parent element. If there is relative in the parent element, then the position of the element is the calculated result. That is, the reference object for absolute positioning is "the last positioned parent element (static does not count)". Absolute positioning causes the element to be removed from the document flow.
fixed (fixed positioning): The reference object of fixed positioning is always the current document. Using fixed positioning, it is easy to position a div in the upper left, upper right, etc. of the browser document.

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