Skip to content

Instantly share code, notes, and snippets.

@bryanrsebastian
Last active September 13, 2018 01:22
Show Gist options
  • Save bryanrsebastian/359ef49ba720d3e6cef70e310ae583f6 to your computer and use it in GitHub Desktop.
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.
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