Skip to content

Instantly share code, notes, and snippets.

@bryanrsebastian
Last active September 20, 2017 01:06
Show Gist options
  • Save bryanrsebastian/a2d2be8f10d47b958eb080bbb48539e9 to your computer and use it in GitHub Desktop.
Save bryanrsebastian/a2d2be8f10d47b958eb080bbb48539e9 to your computer and use it in GitHub Desktop.
By using this function you can set the height of all elements dynamically base on the max height of the selector.
( function( $ ) {
/**
* Script On Document Ready
*/
autoHeight( '[selector]' );
/**
* Script On Resize
*/
$( window ).resize( function() {
autoHeight( '[selector]' );
} );
/**
* Functions
*/
function autoHeight( resource ) {
$( resource ).height( 'auto' );
var maxHeight = Math.max.apply( null, $( resource ).map( function() {
return $( this ).height();
} ).get() );
$( resource ).height( maxHeight );
}
} ( jQuery ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment