Created
April 24, 2011 14:10
-
-
Save sindresorhus/939568 to your computer and use it in GitHub Desktop.
jQuery plugin - Equalize the elements to the same size - width or 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
$.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