Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created April 24, 2011 14:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sindresorhus/939568 to your computer and use it in GitHub Desktop.
Save sindresorhus/939568 to your computer and use it in GitHub Desktop.
jQuery plugin - Equalize the elements to the same size - width or height.
$.fn.sameSize = function( width, max ) {
var prop = width ? 'width' : 'height',
size = Math.max.apply( null, $.map( this, function( elem ) {
return $( elem )[ prop ]();
})),
max = size < max ? size : max;
return this[ prop ]( max || size );
};
// same height
$('div').sameSize();
// same width
//$('div').sameSize(true);
// same width, and max constraint
//$('div').sameSize(true, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment