Js to get the size and mouse coordinates of various windows

Source: Internet
Author: User

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
Webpage text height: document. body. scrollHeight
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. availWidthVar t = "";

Obtain the mouse position:

Event. clientX is the distance from the mouse to the left side of the browser, event. clientY is the distance from the mouse village to the edge of the page, but positioning is not only this way, you need to consider that the current page coordinate is not the location of the mouse (such as dragging the webpage scroll bar to the bottom right ), therefore, we need to add the following content:

Var x = event. clientX + document. body. scrollLeft;

Var y = event. clientY + document. body. scrollTop;

Extends umentElement. scrollTop and document.doc umentElement. scrollLeft. Otherwise, the scroll value is 0.

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.