Detailed description of the offsetleft attribute usage in javascript and the javascript Closure

Source: Internet
Author: User

Detailed description of the offsetleft attribute usage in javascript and the javascript Closure

This attribute returns the distance between the current element and the left edge of a parent element. Of course, this parent element is also exquisite.

(1) If the parent element contains a positioning element, the distance from the edge of the positioning element closest to the current element is returned.
(2) If no positioning element exists in the parent element, the distance from the left edge of the parent element to the body is returned.

Syntax structure:

Obj. offsetleft

Note: This attribute is read-only and cannot be assigned a value.

Code example:

<! DOCTYPE html> 

The above code returns the distance from the inner element to the left of the main element, because the main element is the first parent element to be located.

<! DOCTYPE html> 

The above code returns the size of the inner element from the left side of the body element.

This attribute has certain compatibility issues. For more information, see offsetleft compatibility introduction.

Ps: What is the specific role of the offsetLeft attribute in js?

You can determine the left distance between an object and the document, that is, the left edge of the browser. For example, if you write a div to get this div, then alert (your div. offsetLeft) will be able to see the distance from the left side of the browser. Of course, you can also use it to assign values to objects. The offset is not only Left, but also offsetTop offsetWidth offsetHeight, which is a useful attribute in JS.

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.