The use and difference of the offset and position of JQ

Source: Internet
Author: User

  1. Offset: Gets the current coordinates of the element relative to the document
  2. Attention
  3. Using the offset () method, regardless of how the element is positioned or how its parent element is positioned, is the offset of the element relative to the current viewport.
  4. Postion: Gets the offset of the element relative to the parent element
  5. Attention:
  6. 1, when using the position () method, the fact is that the element is handled with absolute positioning, which is the equivalent of the nearest offset position of the parent element with absolute or relative positioning.
  7. 2, when using the position () method, if all of its parent elements are in the default positioning (static) mode, they are handled in the same way as offset (), which is the relative offset of the current window.
  8. Usage: such as var position=$ (this). Position () defines the current element and the current element Css:position:absolute
  9. Alert (position.top), alert (position.left) outputs the current element distance from the nearest parent element of the vertical distance value and the horizontal distance value note the current element of the father element of the CSS is best for position:relative

The use and difference of the offset and position of JQ

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.