How to obtain element dimensions and coordinates in jquery _ jquery

Source: Internet
Author: User
This article describes how to obtain element dimensions and coordinates in jquery. 1. Obtain coordinates

1. offset ()

The offset () method returns or sets the offset (location) of the matching element relative to the document ). (That is, the viewport coordinates)

The object returned by this method contains two integer attributes: top and left, in pixels.

This method is only valid for visible elements.

2. position ()

The position () method returns the position (offset) of the matching element relative to the parent element ). (Relative to the document coordinate of the parent element)

The object returned by this method contains two integer attributes: top and left, in pixels.

This method is only valid for visible elements.

3. offsetParent ()

The offsetParent () method returns the most recent ancestor location element.

A positioning element refers to an element whose CSS position attribute is set to relative, absolute, or fixed.

You can use jQuery to set the position, or use the position attribute of CSS.

Ii. Obtain dimensions

1. width () and height () Methods

The width () method is used to set or return the width of an element (excluding the padding, border, or margin ).

The height () method sets or returns the height of an element (excluding the padding, border, or margin ).

2. innerWidth () and innerHeight () Methods

The innerWidth () method returns the width (including the padding) of the element ).

The innerHeight () method returns the height of the element (including the padding ).

3. outerWidth () and outerHeight () Methods

The outerWidth () method returns the width of the element (including the padding and border ).

The outerHeight () method returns the height of an element, including the padding and border ).

The outerWidth (true) method returns the width of the element (including the padding, border, and margin ).

The outerHeight (true) method returns the height of an element, including the padding, border, and margin ).
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.