Highly adaptive, pixel (px)-based height adaptation for single pages

Source: Internet
Author: User

/*highly adaptive based on Pixel (px), suitable for single pages*///Set the height (extend to the bottom of the browser or extend to the bottom of the reference element to set the amount of reduction)$.fn.fnsetheight =function(A, B) {if( This. length > 0) {        //parameter Handling        var$Reference, decrease; Switch(arguments.length) { Case0: $Reference=$ (window); Decrease= 0;  Break;  Case1:                if(typeofA = = = ' Number ') {$Reference=$ (window); Decrease=A; } Else{$Reference= $ (A). EQ (0); Decrease= 0; }                 Break; default: $Reference= $ (A). EQ (0); Decrease=B; }        //Set Height        if($Reference. length > 0) {            varIsWindow = $Reference [0] = = =window;  This. each (function() {                varSetHeight =function(target) {var$target =$ (target); varTa_offsettop =$target. Offset (). Top, Re_offsettop= IsWindow? 0: $Reference. Offset (). Top; varTa_top = parseint ($target. css (' padding-top ')) + parseint ($target. css (' border-top-width '))), Re_top= IsWindow? 0:parseint ($Reference. css (' padding-top ')) + parseint ($Reference. css (' border-top-width '))); varh = $Reference. Height () + re_top-(ta_offsettop-re_offsettop)-Ta_top-decrease;                $target. Height (parseint (h));                }; SetHeight ( This); //Preparing the Resize event for a form (adding methods and properties to the DOM in a closure)                if(! This. Executionsequence) {if(!window.__setheightexecutionsequence) window.__setheightexecutionsequence = 1;  This. setheight =function() {//Add method to dom: set heightSetHeight ( This);                    };  This. Executionsequence = window.__setheightexecutionsequence;//add attributes to DOM: Record execution orderwindow.__setheightexecutionsequence++; $( This). addclass (' Resize-setheight ');        }            }); }    }    return  This;};//wraps the Resize event of a form to prevent multiple triggersWindow. Win_resize =function(Func, time) {varIsrun =true, time= Time!== 0? Time | | 250:0; $ (window). Resize (function(e) {if(isrun) {Isrun=false; SetTimeout (function() {Isrun=true;            Func (e);        }, time); }    });};//highly adaptive to the currently visible viewwindow. $CurrentView = $ ();//the selector needs to be updated in the corresponding event ...Window. Resizesetheight =function() {    var$target = $CurrentView. Find ('. resize-setheight:visible ')); varArraydom =$.makearray ($target); //queued in order of executionArraydom.sort (function(A, b) {returnA.executionsequence-b.executionsequence;    }); //dequeue Execution     for(vari = 0; i < arraydom.length; i++) {arraydom[i].setheight (); }};//Binding EventsWin_resize (Resizesetheight, 500);//highly adaptive when form resize$ (' #xxx '). On (' click ', '. xxx '),function() {//other events are highly adaptive, such as when tabs switch ...    if(XXX) {$ (window). Resize ();//or: Resizesetheight ();    }});//setheight use case, selector can be: string | | JQ Object | | Dom Object$ (' #xxx '). Fnsetheight ();//extend to the bottom of the browser$ (' #xxx '). Fnsetheight (20);//extends to the bottom of the browser and reduces 20px$ (' #xxx '). Fnsetheight (' #reference ');//extends to the bottom of the reference element$ (' #xxx '). Fnsetheight (' #reference ', 20);//extends to the bottom of the reference element and reduces the 20px

Highly adaptive, pixel (px)-based height adaptation for single pages

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.