JavaScript Tutorial Series 46:js three series-Convenient offset family

Source: Internet
Author: User

1 Offset family

The word offset is itself-the meaning of offset, compensation, and displacement. JS in a set of convenient way to get the element size is the offset family;

2  The offset structure is described as:

3 Offset Common Properties

1 offsetwidth offsetheight Get the width and height of the object (own, unrelated to others)

Offsetwidth = Width+padding+border

2 offsetleft OffsetTop Returns the position to the left of the upper box (with positioning) if the parent is not positioned, the body will prevail

Offsetleft the father's border from his father's padding.

3 offsetParent:

-1 Returns the parent of the object (with positioning) if the parent element of the current element is not CSS-positioned (position is absolute or relative,fixed), offsetparent is body.

2 If there is a CSS anchor in the parent element of the current element (position is absolute or relative,fixed), Offsetparent takes the nearest parent element.

4 the difference between OffsetTop & Style.top

1 The biggest difference is that the OFFSETTOP can return to the left of the distance without locating the box. and Style.top can not

-2 OffsetTop Returns a number, and Style.top returns a string with a unit in addition to the number: px.

-3 OffsetTop Read Only, while Style.top can read and write.

4 If the top style is not specified for the HTML element, Style.top returns an empty string.

JavaScript Tutorial Series 46:js three series-Convenient offset family

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.