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.