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
Full text of the web page: document.body.scrollHeight
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+:
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
(It should be mentioned that the margin attribute in CSS has nothing to do with clientWidth, offsetWidth, clientHeight, and offsetHeight)
-------------------
Technical Highlights
The code in this section mainly uses some properties of the Document object about the window. The main functions and usage of these properties are as follows.
To get the window size, different properties and methods need to be used for different browsers: to detect the true size of the window, you need to use the Window attributes under Netscape; to detect the body in IE; to get the window size, you need to pay attention to the size of the root element, not the element.
The innerWidth property of the Window object contains the internal width of the current window. The innerHeight property of the Window object contains the internal height of the current window.
The body attribute of the Document object corresponds to the tag of the HTML document. The documentElement property of the Document object represents the root node of the HTML document.
document.body.clientHeight represents the current height of the window where the HTML document is located. document.body.clientWidth represents the current width of the window where the HTML document resides.
A little research on getting the size of visible windows in various browsers.
In my local test: it can be used under IE, FireFox, and Opera
document.body.clientWidth
document.body.clientHeight can be obtained, it is very simple and convenient.
In the company's project: Opera is still used
document.body.clientWidth
document.body.clientHeight
But IE and FireFox use
document.documentElement.clientWidth
document.documentElement.clientHeight
It turns out that the W3C standard is causing trouble http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
If you add this line to the page
In IE: document.body.clientWidth ==> BODY object width
document.body.clientHeight ==> BODY object height
document.documentElement.clientWidth ==> Visible area width
document.documentElement.clientHeight ==> Visible area height
In FireFox: document.body.clientWidth ==> BODY object width
document.body.clientHeight ==> BODY object height
document.documentElement.clientWidth ==> Visible area width
document.documentElement.clientHeight ==> Visible area height?
In Opera: document.body.clientWidth ==> Visible area width
document.body.clientHeight ==> Visible area height
document.documentElement.clientWidth ==> Page object width (i.e. BODY object width plus Margin width) document.documentElement.clientHeight ==> Page object height (i.e. BODY object height plus Margin height)
If there is no standard for W3C,
Then IE is: document.documentElement.clientWidth ==> 0
document.documentElement.clientHeight ==> 0
FireFox is: document.documentElement.clientWidth ==> Page object width (i.e. BODY object width plus Margin width)
document.documentElement.clientHeight ==> Page object height (i.e. BODY object height plus Margin height)
Opera is: document.documentElement.clientWidth ==> Page object width (i.e. BODY object width plus Margin width)
document.documentElement.clientHeight ==> Page object height (i.e. BODY object height plus Margin height)
It's really a hassle. In fact, from the perspective of front-end design and development, it's better to have fewer objects and methods than to not use the latest standards. But if you can't keep up with the trend, you will never be a senior designer, so we must still understand and master this knowledge.