Javascript obtains the window (container) size and position parameters and provides a brief description.

Source: Internet
Author: User

Javascript obtains the size and position of a window (container). Many things are easy to confuse. Here we will give a brief description:

Attribute method description:
The horizontal coordinate of clientX relative to the document;
The vertical coordinate of clientY relative to the document;
Horizontal coordinates of offsetX relative to the container;
Vertical coordinate of offsetY relative to container;
ScrollWidth: get the scroll width of the object;
ScrollHeight: obtains 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 gets the distance between the top of the object and the top of the visible content in the window;
OffsetWidth: gets the width of the object relative to the layout or the parent coordinate specified by the parent coordinate offsetParent attribute;
OffsetHeight: gets the height of the 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 the object relative to the layout or the parent coordinate specified by the offsetTop attribute.

How to obtain screen and window size using Javascript:
Screen Resolution height: window. screen. height;
Screen Resolution width: window. screen. width;
Available screen workspace height (excluding the taskbar): window. screen. availHeight;
Available workspace width (excluding the taskbar): window. screen. availWidth;
Visible area width (excluding the scroll bar and border): document. body. clientWidth;
The visible area of the webpage is high (excluding the scroll bar and border): document. body. clientHeight;
Visible area width of the webpage (including the scroll bar and border): document. body. offsetWidth;
The visible area of the webpage is high (including the scroll bar and border): document. body. offsetHeight;
Webpage body width: document. body. scrollWidth;
Webpage body height: document. body. scrollHeight;
The height of the page to be rolled: document. body. scrollTop;
Left of the webpage to be rolled: document. body. scrollLeft;
On the webpage body (the leftmost distance from the webpage body to the left edge of the screen): window. screenTop;
The left part of the webpage body (the distance between the top part of the webpage body and the edge of the screen): window. screenLeft.

Note: Sometimes the value cannot be obtained because the document type is added to the html file header.:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">,
In this case. body. scrollTop and document. body. changed scrollLeft to document.doc umentElement. scrollTop and document.doc umentElement. scrollLeft, document. body. clientWidth and document. body. change clientHeight to document.documentelement.clientwidthand document.doc umentElement. clientHeight

Of course there are still omissions or unclear points. You can add, discuss, or Baidu to make progress together! Ye ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.