This article mainly introduces JS to get a brief introduction of various width and height. If you need it, you can refer to it. Sometimes, js will be used in the project to get the element location to locate the element, first, the relationship between scrollWidth, clientWidth, and offsetWidth is illustrated through the image.
JS to get a brief introduction to various widths and heights:
ScrollHeight: gets the scroll height of an object.
ScrollLeft: sets or obtains the distance between the left-side border of the object and the leftmost end of the currently visible content in the window.
ScrollTop: sets or obtains the distance between the top of the object and the top of the visible content in the window.
ScrollWidth: gets the scroll width of an object.
OffsetHeight: gets the height of an object relative to the layout or the parent coordinate specified by the parent coordinate offsetParent attribute.
OffsetLeft: obtains the left position of the object relative to the layout or the parent coordinate specified by the offsetParent attribute.
OffsetTop: obtains the top position of an object relative to the layout or the parent coordinate specified by the offsetTop attribute.
The horizontal coordinates of event. clientX relative to the document
The vertical coordinates of event. clientY relative to the document
Horizontal coordinates of event. offsetX relative to the container
Event. offsetY vertical coordinates of the container
Document.doc umentElement. scrollTop vertical scroll Value
Event.clientxw.document.doc umentElement. The horizontal coordinate of scrollTop relative to the document + The amount of vertical scrolling
The difference between FireFox and IE is as follows:
IE6.0, FF1.06 +:
ClientWidth = width + padding
ClientHeight = height + padding
OffsetWidth = width + padding + border
OffsetHeight = height + padding + border
IE5.0/5.5:
ClientWidth = width-border
ClientHeight = height-border
OffsetWidth = width
OffsetHeight = height
(The margin attribute in CSS is independent of clientWidth, offsetWidth, clientHeight, and offsetHeight)
OffsetWidth (width + padding + border)
Assume that obj is an HTML control.
Obj. offsetTop refers to the position of the obj control above or upper layer. It is an integer in pixels.
Obj. offsetLeft refers to the position of the obj control on the left or upper layer. It is an integer in pixels.
Obj. offsetWidth refers to the width, integer, and unit pixel of the obj control. Obtains the width of the visible content of an object, excluding the scroll bar and border;
Obj. offsetHeight refers to the height, integer, and unit pixel of the obj control.
OffsetWidth and style. width
1. offsetTop returns numbers, while style. top returns strings. In addition to numbers, it also has the unit: px.
Ii. offsetTop read-only, while style. top can be read and written.
3. If the top style is not specified for the HTML element, style. top returns an empty string.