Use jquery to adapt browser-wide controls to browser size

Source: Internet
Author: User

Use jquery to adapt browser-wide controls to browser size

First, add a reference to jquery in

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

Add methods in JS Window.onresize and window.onload The method is a system function and is called automatically when there is a trigger.

<script type= "Text/javascript" >        window.onresize = function () {        var Width = document.body.offsetwidth;// Read the browser's wide        //document.getelementbyid ("ChartData"). width = width;        $ ("#ChartData"). CSS ({"width": width.tostring () + "px"});//use jquery to adjust the width of the control        document.getElementById ("Show_size") . InnerHTML = width + "  " + document.body.offsetheight;//display current browser width        //alert (document.getElementById ("Show_size "). value);  chartframe//loading page is called    }    window.onload = window.onresize;</script>

Another way to read the browser size is as follows:

Gets the window width if (window.innerwidth) Winwidth = Window.innerwidth;else if ((document.body) && ( document.body.clientWidth)) Winwidth = document.body.clientwidth;//Gets the window height if (window.innerheight) Winheight = Window.innerheight;else if ((document.body) && (document.body.clientHeight)) Winheight = document.body.clientheight;//detects the body by deep inside the Document and gets the window size if (document.documentelement && Document.documentElement.clientHeight && document.documentElement.clientWidth) {winheight = Document.documentelement.clientheight;winwidth = Document.documentElement.clientWidth;}
With:




Use jquery to adapt browser-wide controls to browser size

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.