This article mainly introduces jquery's method of getting the absolute and relative positions of html elements. If you need them, refer to the absolute coordinates:
The Code is as follows:
$ ("# Elem"). offset (). top
$ ("# Elem"). offset (). left
Coordinates of the parent element:
The Code is as follows:
$ ("# Elem"). position (). top
$ ("# Elem"). position (). left
In addition:
Static (default): the default Positioning method.
Relative (relative positioning): based on static, the original positions of relative elements are changed by setting top, bottom, left, and right.
Absolute (absolute positioning): relative to the parent element. If the parent element contains relative, the position of this element is calculated. That is, the reference object for positioning absolute is "the parent element that was located previously (static is not counted )". Absolute positioning will delete the elements from the document stream.
Fixed: The reference object for fixed positioning is always the current document. With fixed positioning, it is easy to place a p position on the top left and top right of the browser document.