Last active
September 13, 2018 01:22
-
-
Save bryanrsebastian/359ef49ba720d3e6cef70e310ae583f6 to your computer and use it in GitHub Desktop.
Make the height of all elements with the selected class becomes automatic depends on the maximum height.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( function( $ ) { | |
if( $( window ).width() > 750 ) { | |
autoHeight( '.__your_class' ); | |
} else { | |
$( '.__your_class' ).height( 'auto' ); | |
} | |
$( window ).resize( function() { | |
if( $( window ).width() > 750 ) { | |
autoHeight( '.__your_class' ); | |
} else { | |
$( '.__your_class' ).height( 'auto' ); | |
} | |
} ); | |
/** | |
* Make the height of all elements with the selected class becomes automatic depends on the maximum height. | |
* @param {[string]} resource [selected class] | |
* @return {[void]} [automatic change height] | |
*/ | |
function autoHeight( resource ) { | |
$( resource ).height( 'auto' ); | |
var maxHeight = Math.max.apply( null, $( resource ).map( function() { | |
return $( this ).height(); | |
} ).get() ); | |
$( resource ).height( maxHeight ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment