Home > Web Front-end > JS Tutorial > js code to get page and element height and width_javascript skills

js code to get page and element height and width_javascript skills

WBOY
Release: 2016-05-16 15:03:45
Original
2037 people have browsed it

Visible area width of web page: document.body.clientWidth;
The height of the visible area of ​​the web page: document.body.clientHeight;
The width of the visible area of ​​the web page: document.body.offsetWidth (including the width of the edges and scroll bars);
The height of the visible area of ​​the web page: document.body.offsetHeight (including the width of the edge);
Full text width of web page body: document.body.scrollWidth;
Full text height of web page body: document.body.scrollHeight;
The height at which the web page is scrolled (ff): document.body.scrollTop;
The height at which the web page is scrolled(ie): document.documentElement.scrollTop;
The left side of the web page being scrolled: document.body.scrollLeft;
On the main body of the web page: window.screenTop;
Left part of the web page text: window.screenLeft;
The width of an element: obj.offsetWidth;
The height of an element: obj.offsetHeight;
The distance from the upper border of an element to the top of the body: obj.offsetTop; (when the containing element does not contain a scroll bar)
The distance from the left border of an element to the leftmost side of the body: obj.offsetLeft; (when the containing element does not contain a scroll bar)
Returns the offset from the upper edge of the current element to the upper edge of its containing element: obj.offsetTop (in the case where the element's containing element contains scroll bars)
Returns the offset from the left edge of the current element to the left edge of its containing element: obj.offsetLeft (if the element's containing element contains a scroll bar)

scrollTop, scrollLeft

Set or return the number of pixels that have been scrolled to the left or top border of the element. These pixels are only useful if the element has scrollbars, for example if the element's CSS overflow property is set to auto. These properties are also only defined on the document's or tag (this is browser dependent), and together they specify the position of the scrolling document. Note that these properties do not specify the amount of scrolling for an