In the first article, let's talk about the offsetParent attribute in Javascript.
Supported browsers: Internet Explorer 4.0 +, Mozilla 1.0 +, Netscape 6.0 +, Opera 7.0 +, and Safari 1.0 +
Element. offsetParent
Summary
OffsetParent returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element. if the element is non-positioned, the root element (html in standards compliant mode; body in quirks rendering mode) is the offsetParent. offsetParent returns null when the element has style. display set to "none ".
Syntax
ParentObj = element. offsetParent
Parameters
· ParentObj is an object reference to the element in which the current element is offset.
Specification
DOM Level 0. Not part of specification.
Excerpted from the Mozilla Developer Center website
Translation:
Element. offsetParent
Summary
The offsetParent attribute returns an object reference. This object is closest to the element that calls offsetParent (the closest to the contained level) and is a container element that has been positioned by CSS. If the container element is not CSS located, the offsetParent attribute is referenced by the root element (in standard compatibility mode, html element, and body element in weird rendering mode. When the style. display of the container element is set to "none" (except for IE and Opera), The offsetParent attribute returns null.
Syntax
ParentObj = element. offsetParent
Variable
· ParentObj is an element reference. The offset of the current element is calculated.
Specifications
DOM Level 0. Not part of the Specification.
<! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd"> <ptml> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> Untitled Document </title> </pead> <body onload =" offset_init () "> <p id =" sonObj "> test the OffsetParent attribute </p> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]