Jquery's method of getting the absolute and relative positions of html elements

Source: Internet
Author: User

Absolute coordinate:

Copy codeThe Code is as follows:
$ ("# Elem"). offset (). top
$ ("# Elem"). offset (). left

Coordinates of the parent element:

Copy codeThe 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 div on the top left and top right of the browser document.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.