Quick actions

cmd+k|ctrl+k

Navigation

Languages

Estimate Height of Elements

Snippet info

Language

JavaScript

Visibility

public

Author

horngyih

Created

2017-08-12T04:13:44Z

Updated

2017-08-12T04:23:31Z

var estimateHeight = function( target ){
    console.log( "Estimate Height : ", target );
    var total = 0;
    if( typeof target === "string" ){
        console.log( "Estimate Height : SELECTOR : " );
        total = estimateHeight( document.querySelectorAll( target ) );
    }
    if( target instanceof HTMLElement ){
        console.log( "Estimate Height : ELEMENT : " );
        total = target.offsetHeight;
    } else if( target instanceof NodeList ){
        console.log( "Estimate Height : NODELIST : " );
        for( var i = 0; i < target.length; i++ ){
            total += estimateHeight( target[i] );
        }
    } else if( Array.isArray( target ) ){
        console.log( "Estimate Height : Array<SELECTOR> : " );
        total = target.reduce((total,current)=>{
              total = total || 0;
              total += estimateHeight( current );
              return total;
        },0);
    }
    console.log( "Total => ", total );
    return total
};
INFO