JQuery height () innerheight () outerhight () width () innerwidth () outerwidth () Source code interpretation

Source: Internet
Author: User


On the second level each, the object passed in with a height example is this,

It iterates through the call function (Defaultextra,funcname), which means that the incoming Defaultextra is the key padding/content/"", and FuncName is the corresponding innerheight,height, Outerheight.

Jquery.fn[funcname] has four branches inside:
1, $ (window). Height ()
Then return directly to Window.document.documentElement.clientHeight

2, $ (document). Height ()
                    return Math.max (                        "scroll" + name], doc["scroll" +                        name], "offset" + name], doc["offset" + nam E],                        "client" + name]                    );

It is obvious that it returns the maximum value in these 5 values.

3, if the value, call JQUERY.CSS ()

4, if it is an assignment, call Jquery.style ()

Finally, these two branches are more complex inside, jquery.css,csshooks,cssprops is the focus = =, and so on after the detailed look at the time to write it.

Jquery.each ({height: "height", Width: "width"},function(name, type) {Jquery.each ({padding:"Inner" + name, Content:type, "": "outer" + name},function(Defaultextra, funcName) {//Margin is only for outerheight, Outerwidthjquery.fn[FuncName] =function(margin, value) {varchainable = Arguments.length && (Defaultextra | |typeofMargin!== "Boolean"), Extra= Defaultextra | | (Margin = = =true|| Value = =true? "Margin": "Border" ); returnAccess This,function(Elem, type, value) {varDoc; if(Jquery.iswindow (elem)) {//as of 5/8/2012 this would yield incorrect results for Mobile Safari, but there                    //isn ' t a whole lot we can do. See pull request at the this URL for discussion:                    //https://github.com/jquery/jquery/pull/764                    returnelem.document.documentelement["Client" +name]; }                //Get Document width or height                if(Elem.nodetype = = 9) {Doc=elem.documentelement; //either Scroll[width/height] or offset[width/height] or client[width/height],                    //whichever is greatest                    returnMath.max (elem.body["Scroll" + name], doc["scroll" +name], elem.body["offset" + name], doc["offset" +name], doc["Client" +name]); }                returnValue = = undefined?//Get width or height on the element, requesting and not forcing parsefloatjquery.css (Elem, type, extra)://Set width or height on the elementJquery.style (Elem, type, value, extra); }, type, chainable? margin:undefined, Chainable,NULL );    }; });});

JQuery height () innerheight () outerhight () width () innerwidth () outerwidth () Source code interpretation

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.