Code that implements adaptive height identical between left and right div Based on jQuery

Source: Internet
Author: User

Online Demo: http://demo.jb51.net/js/2012/jquery_demo/jquery_div_autoheihet.htm
Complete code:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> jQuery achieves completely the same adaptive height of left and right divs-script house </title>
<Meta name = "Copyright" content = "script sharing network http://www.jb51.net/"/>
<Meta name = "description" content = "jQuery achieves completely the same adaptive height of left and right div"/>
<Meta content = "jQuery achieves completely the same adaptive height for left and right divs, JavaScript, sharing, and JavaScript code" name = "keywords"/>
<Style type = "text/css">
<! --
Body {FONT-SIZE: 14px; background-color: # fff}
-->
</Style>
<Style type = "text/css">
# Left {background: #999999; float: left; width: 100px ;}
# Right {background: # 0066FF; color: # fff; width: 300px; float: left ;}
. Clear {clear: both ;}
</Style>
</Head>
<Body>
<H3> left side of the height on the right <Div id = "left">
<Div style = "padding: 10px">
<A href = "http://www.jb51.net"> foot home </a>
</Div>
</Div>
<Div id = "right">
<Div style = "padding: 10px">
Is a website design-related resource sharing site, the site only provides the best <a href = "http://www.jb51.net/"> JS Code </a>, jQuery plug-in, web effects, HTML5 code, vector graphs, design icons, website templates, and so on, all of which are free of charge.
</Div>
</Div>
<Script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"> </script>
<Script type = "text/javascript">
Function $ (id ){
Return document. getElementById (id)
}
Function getHeight (){
If ($ ("left"). offsetHeight >=$ ("right"). offsetHeight ){
$ ("Right"). style. height = $ ("left"). offsetHeight + "px ";
}
Else {
$ ("Left"). style. height = $ ("right"). offsetHeight + "px ";
}
}
Window. onload = function (){
GetHeight ();
}

</Script>
<Div style = "clear: both"> </div>
</Body>
</Html>

Here, clientHeight, which is highly used in jquery code, describes several different methods of obtaining and their differences.
These four browsers are IE (Internet Explorer), NS (Netscape), Opera, and FF (FireFox ).
ClientHeight
Everyone has no objection to clientHeight and thinks it is the height of the visible area of the content, that is, the height of the area where the content can be viewed in the browser of the page, generally, the area below the last toolbar to above the status bar is irrelevant to the page content.
OffsetHeight
IE and Opera think offsetHeight = clientHeight + scroll bar + border.
NS and FF hold that offsetHeight is the actual height of the webpage content, which can be smaller than clientHeight.
ScrollHeight
IE and Opera hold that scrollHeight is the actual height of the webpage content, which can be smaller than clientHeight.
NS and FF think that scrollHeight is the height of the webpage content, but the minimum value is clientHeight.
Simply put
ClientHeight is the height of the area where the content is viewed through the browser.
NS and FF hold that both offsetHeight and scrollHeight are the content height of the webpage. However, when the content height of the webpage is less than or equal to clientHeight, the value of scrollHeight is clientHeight, while the value of offsetHeight can be less than clientHeight.
IE and Opera hold that offsetHeight is the clientHeight scroll bar and border in the visible area. ScrollHeight indicates the actual height of the webpage content.
Likewise
The description of clientWidth, offsetWidth, and scrollWidth is the same as above. You only need to change the height to the width.

Description
The above is based on dtd html 4.01 Transitional. If it is dtd xhtml 1.0 Transitional, the meaning will be different. In XHTML, all three values are the same value, indicating the actual height of the content. Most new browsers support different interpreters based on the DOCTYPE specified on the page. Download or browse the test file.
Link formula: scrollHeight = offsetHeight + scrollTop

Ps: introduction from Baidu encyclopedia

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.