JavaScript: webpage, browser, screen height, and width summarization _ javascript skills

Source: Internet
Author: User
This article provides a summary of how JavaScript can be used to obtain webpages, browsers, screen heights, and widths. It is often found that when writing JavaScript, the height and width of the webpage, browser, or screen are used to solve the layout and positioning problem. I often forget it before using it, or search on the Internet, simply summarize it by yourself. This makes it easy to use again, saving time and effort.

Visible area width of the webpage: document. body. clientWidth
Visible area height: document. body. clientHeight
Visible area width of the webpage: document. body. offsetWidth (including the width of the edge)
Visible area height of the webpage: document. body. offsetHeight (including the width of the edge)
Webpage text width: document. body. scrollWidth (with scroll bar width)
Webpage text height: document. body. scrollHeight (with scroll bar height)
The height of the page to be rolled: document. body. scrollTop
Left: document. body. scrollLeft
Page body: window. screenTop
Page body part left: window. screenLeft
Screen resolution height: window. screen. height
Screen resolution width: window. screen. width
Available screen workspace height: window. screen. availHeight
Available workspace width: window. screen. availWidth

Precise HTML positioning: scrollLeft, scrollWidth, clientWidth, and offsetWidth
ScrollHeight: Gets 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 obtains the distance between the top of the object and the top of the visible content in the window.
ScrollWidth: Gets the scroll width of an object.
OffsetHeight: Gets the height of an 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 an object relative to the layout or the parent coordinate specified by the offsetTop attribute.
The horizontal coordinates of event. clientX relative to the document
The vertical coordinates of event. clientY relative to the document
Horizontal Coordinates of event. offsetX relative to the container
Event. offsetY vertical coordinates of the container
Document.doc umentElement. scrollTop vertical scroll value
Event.clientxw.document.doc umentElement. the horizontal coordinate of scrollTop relative to the document + the amount of vertical scrolling

The differences between IE and FireFox are as follows:

IE6.0, FF1.06 +:

The code is as follows:


ClientWidth = width + padding
ClientHeight = height + padding
OffsetWidth = width + padding + border
OffsetHeight = height + padding + border

IE5.0/5.5:

The code is as follows:


ClientWidth = width-border
ClientHeight = height-border
OffsetWidth = width
OffsetHeight = height

Summary: There are a lot of things about height and width, but some of them do not understand it. I tried it myself. some of the values obtained are the same, which is confusing, it depends on the situation.

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.