jquery Gets the code for the width and height of the browser screen

Source: Internet
Author: User

Get the size of the screen

I started to have a problem, I want to do a pop-up div layer, and then set the Z-index properties and height and width background color, etc.
I'm using $ (document). Height (), $ (document). Width () to get the height and width of the window, but when you double-click the browser to change the size of the window, this height does not change ...

The code is as follows Copy Code

CSS Code

<style type= "Text/css" >
#cover {
width:100%;
Background-color: #CCCCCC;
z-index:99;
Display:none;
}
</style>


HTML Code

<body>
<input type= "button" id= "BTN" value= "Show"/>
<div id= "Cover" ></div>
</body>


JScript Code


var btn = $ ("#btn");
var show = $ ("#cover");
Btn.click (function () {
Show.css ({"position": "Absolute", "Top": "0", "Left": "0"});
Show.height ($ (document). Height ());
Show.show ();
});
</script>


Then Baidu found some about jquery get the width and height code of the browser screen

The code is as follows Copy Code


$ (document). Ready (function () {
Alert ($ (window). Height ()); Browser current window visual area height
Alert ($ (document). Height ()); The height of the browser's current window document
Alert ($ (document.body). Height ());//browser Current window document body level
Alert ($ (document.body). Outerheight (True))//Browser Current window document body's total height includes border padding margin
Alert ($ (window). width ()); Browser current window visual area width
Alert ($ (document). width ());//browser Current window Document object widths
Alert ($ (document.body). width ());//browser Current window document body widths
Alert ($ (document.body). Outerwidth (True))//Browser The total width of the body of the current window document includes border padding margin
})


Gets the height width of the current screen

The code is as follows Copy Code


<script type= "Text/javascript" >
$ (document). Ready (function ()
{
Alert ($ (window). Height ()); Browser current window visual area height
Alert ($ (document). Height ()); The height of the browser's current window document
Alert ($ (document.body). Height ());//browser Current window document body level
Alert ($ (document.body). Outerheight (True))//Browser Current window document body's total height includes border padding margin
Alert ($ (window). width ()); Browser current window visual area width
Alert ($ (document). width ());//browser Current window Document object widths
Alert ($ (document.body). width ());//browser Current window document body height
Alert ($ (document.body). Outerwidth (True))//Browser The total width of the body of the current window document includes border padding margin
}
)
</script>


Browser compatibility used, so on the internet to find some of the summary.

The code is as follows Copy Code

Alert ($ (window). Height ()); Browser current window visual area height

Alert ($ (document). Height ()); The height of the browser's current window document

Alert ($ (document.body). Height ());//browser Current window document body level

Alert ($ (document.body). Outerheight (True))//Browser Current window document body's total height includes border padding margin

Alert ($ (window). width ()); Browser current window visual area width

Alert ($ (document). width ());//browser Current window Document object widths

Alert ($ (document.body). width ());//browser Current window document body height

Alert ($ (document.body). Outerwidth (True))//Browser The total width of the body of the current window document includes border padding margin

Get the height, width of the page

function GetPageSize () {

var xscroll, Yscroll;

if (window.innerheight && window.scrollmaxy) {

Xscroll = window.innerwidth + Window.scrollmaxx;

Yscroll = Window.innerheight + window.scrollmaxy;

} else {

if (Document.body.scrollHeight > Document.body.offsetHeight) {//all but Explorer Mac

Xscroll = Document.body.scrollWidth;

Yscroll = Document.body.scrollHeight;

else {//Explorer mac...would also work in Explorer 6 Strict, Mozilla and Safari

Xscroll = Document.body.offsetWidth;

Yscroll = Document.body.offsetHeight;

}

}

var windowwidth, WindowHeight;

if (self.innerheight) {//all except Explorer

if (document.documentElement.clientWidth) {

WindowWidth = Document.documentElement.clientWidth;

} else {

WindowWidth = Self.innerwidth;

}

WindowHeight = Self.innerheight;

} else {

if (document.documentelement && document.documentElement.clientHeight) {//Explorer 6 Strict Mode

WindowWidth = Document.documentElement.clientWidth;

WindowHeight = Document.documentElement.clientHeight;

} else {

if (document.body) {//other explorers

WindowWidth = Document.body.clientWidth;

WindowHeight = Document.body.clientHeight;

}

}

}

For small pages and total height less then height of the viewport

if (Yscroll < WindowHeight) {

PageHeight = WindowHeight;

} else {

PageHeight = Yscroll;

}

For small pages and total width less then width of the viewport

if (Xscroll < windowwidth) {

PageWidth = Xscroll;

} else {

PageWidth = WindowWidth;

}

Arraypagesize = new Array (PageWidth, PageHeight, WindowWidth, windowheight);

return arraypagesize;

}

scroll bar

Document.body.scrollTop;

$ (document). ScrollTop ();

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.