I often find that when writing JavaScript, you need to use the height and width of the web page, browser or screen to solve the layout positioning problem. You often forget it before and after use, or search online, and simply summarize it yourself, so that it is convenient to use it again, saving time and effort.
The visible area width of the web page: document.body.clientWidth
The visible area height of the web page: document.body.clientHeight
The visible area width of the web page: document.body.offsetWidth (including the width of the edge line)
The visible area height of the web page: document.body.offsetHeight (including the width of the edge line)
Full text width of the web page: document.body.scrollWidth (with scroll bar width)
Full text height of the web page: document.body.scrollHeight (with scroll bar height)
The web page is rolled out at a high level: document.body.scrollTop
The left of the web page being rolled out: document.body.scrollLeft
On the main part of the web page: window.screenTop
Left of the main text of the web page: window.screenLeft
High screen resolution: window.screen.height
Width of screen resolution: window.screen.width
Screen Available Workspace Height: window.screen.availHeight
Screen Available Workspace Width: window.screen.availWidth
HTML precise positioning: scrollLeft, scrollWidth, clientWidth, offsetWidth
scrollHeight: Gets the scroll height of the object.
scrollLeft: Set or get the distance between the left boundary of the object and the leftmost end of the currently visible content in the window
scrollTop: Set or get the distance between the top of the object and the top of the visible content in the window
scrollWidth: Get the scroll width of the object
offsetHeight: Gets the height of the object relative to the layout or the parent coordinate specified by the parent coordinate offsetParent property
offsetLeft: Gets the calculated left position of the object relative to the layout or parent coordinates specified by the offsetParent property
offsetTop: Gets the calculated top position of the object relative to the layout or the parent coordinate specified by the offsetTop property
event.clientX horizontal coordinates relative to the document
event.clientY vertical coordinates relative to the document
event.offsetX horizontal coordinates relative to container
event.offsetY vertical coordinates relative to container
document.documentElement.scrollTop The value of scrolling vertically
event.clientX+document.documentElement.scrollTop relative to the horizontal coordinate of the document + the amount of scrolling in the vertical direction
IE, FireFox differences are as follows:
IE6.0, FF1.06+:
The code copy is as follows:
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
IE5.0/5.5:
The code copy is as follows:
clientWidth = width - border
clientHeight = height - border
offsetWidth = width
offsetHeight = height
Summary: There are quite a lot of things about height and width. I haven’t understood some of the specifics myself. After experimenting with them, some of them have the same values, so it is very confusing and can only depend on the situation.