Use JQuery to make browser controls adaptive to browser size

Source: Internet
Author: User

Use JQuery to make browser controls adaptive to browser size

Use JQuery to make browser controls adaptive to browser size

FirstAdd references to jQuery

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>

Add Methods window. onresize and window. onload in JS. This method is a system function and is automatically called when triggered.

<Script type = "text/javascript"> window. onresize = function () {var Width = document. body. offsetWidth; // read the browser width // document. getElementById ("ChartData "). width = Width; $ ("# ChartData" ).css ({"width": Width. toString () + "px"}); // use JQuery to adjust the control width document. getElementById ("show_size "). innerHTML = Width + "" + document. body. offsetHeight; // display the current browser width // alert (document. getElementById ("show_size "). value); ChartFrame // The loading page is called} window. onload = window. onresize; </script>

In addition, the method for reading the browser size is as follows:

// Obtain the window width if (window. innerWidth) winWidth = window. innerWidth; else if (document. body) & (document. body. clientWidth) winWidth = document. body. clientWidth; // obtain the window height if (window. innerHeight) winHeight = window. innerHeight; else if (document. body) & (document. body. clientHeight) winHeight = document. body. clientHeight; // detects the body in the Document to obtain the window size if (document.doc umentElement & document.doc umentElement. clientHeight & document.doc umentElement. clientWidth) {winHeight = document.doc umentElement. clientHeight; winWidth = document.doc umentElement. clientWidth ;}
Details:

<Script> function getInfo () {var s = ""; s = "visible area width of the webpage:" document. body. clientWidth; s = "visible area of the webpage high:" document. body. clientHeight; s = "visible area width of the webpage:" document. body. offsetWidth "(including the width of the edge and scroll bar)"; s = "visible area height of the webpage:" document. body. offsetHeight "(including the edge width)"; s = "webpage text width:" document. body. scrollWidth; s = "webpage text Height:" document. body. scrollHeight; s = "the height of the page to which the page is rolled (ff):" document. body. scrollTop; s = "the height of the page to which the page is rolled (ie):" document.doc umentElement. scrollTop; s = "Left of the webpage to which the page is rolled:" document. body. scrollLeft; s = "Page body part:" window. screenTop; s = "webpage body section left:" window. screenLeft; s = "high screen resolution:" window. screen. height; s = "Screen Resolution width:" window. screen. width; s = "available workspace Height:" window. screen. availHeight; s = "available workspace width:" window. screen. availWidth; s = "your screen setting is" window. screen. colorDepth "color"; s = "Your Screen Settings" window. screen. deviceXDPI "pixels/inches"; // alert (s);} getInfo (); </script>



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.