JavaScript common get page width high information API

Source: Internet
Author: User

In the construction of the page will often need to get some of the width of the page information, such as the implementation of lazy loading the image needs to get the height of the visible area of the page and the height of the scrolled area, to determine whether the picture is visible to determine the time to load the picture,

Take a moment to sort out the API for page width and height information

Continuous finishing ...

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 ==> The width of the page object (that is, the body object width plus the margin width)
Document.documentElement.clientHeight ==> Page Object height (i.e. body object height plus margin height)


And if there is no standard to define the
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) Document.documentElement.clientHeight = = > Page object height (i.e. body object height plus margin)


Opera is:
Document.documentElement.clientWidth ==> Page object width (i.e. body object width plus margin) Document.documentElement.clientHeight = = > Page object height (i.e. body object height plus margin)
Really a troublesome thing, in fact, in terms of development, rather fewer objects and methods, do not use the latest standards to facilitate many AH.

width of visible area of Web page:
Document.body.clientWidth

Web page visible Area High:
Document.body.clientHeight

width of visible area of Web page:
Document.body.offsetWidth (including the width of the edge)

Web page visible Area High:
Document.body.offsetHeight (including the width of the edge)

Page body Full text width:
Document.body.scrollWidth

Page body Full text High:
Document.body.scrollHeight

The page is rolled away High:
Document.body.scrollTop

Window.pageyoffset

Webpage is rolled away left:
Document.body.scrollLeft

Window.pagexoffset

On the body part of the webpage:
Window.screentop

Page body part left:
Window.screenleft

High screen resolution:
Window.screen.height

Width of screen resolution:
Window.screen.width

Screen usable workspace height:
Window.screen.availHeight

Screen Usable workspace width:
Window.screen.availWidth

JavaScript common get page width high information API

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.