Code that JavaScript gets the height of the page and the position of the scroll bar

Source: Internet
Author: User

Http://www.jb51.net/article/23331.htm

JavaScript gets the height of the page and the position of the scroll bar in the code font: [Increase decrease] Type: Reprint JavaScript to get the height of the page and scroll bar position code, the need for friends can refer to the next.Copy CodeThe code is as follows:
var viewport={
Top:function () {
Return Window.pageyoffset
|| Document.documentelement && Document.documentElement.scrollTop
|| Document.body.scrollTop;
},
Height:function () {
Return Window.innerheight
|| Document.documentelement && Document.documentElement.clientHeight
|| Document.body.clientHeight;
},
Left:function () {
Return Window.pagexoffset
|| Document.documentelement && Document.documentElement.scrollLeft
|| Document.body.scrollLeft;
},
Width:function () {
Return window.innerwidth
|| Document.documentelement && Document.documentElement.clientWidth
|| Document.body.clientWidth;
},
Right:function () {
return Viewport.left () + viewport.width ();
},
Bottom:function () {
return Viewport.top () + viewport.height ();
}
};

Center:
Copy CodeThe code is as follows:
style.position= "Absolute";
style.left=50%;
Style.top=viewport.top () +viewport.height ()/2+ "px"; Articles you may be interested in:

Code that JavaScript gets the height of the page and the position of the scroll bar

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.