Skip to content

Instantly share code, notes, and snippets.

@dougwollison
Created January 21, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougwollison/8bed963a15abe55627b5 to your computer and use it in GitHub Desktop.
Save dougwollison/8bed963a15abe55627b5 to your computer and use it in GitHub Desktop.
Get max width/height of a collection of objects.
jQuery.fn.maxDimension = function( property ) {
var max = 0;
jQuery( this ).each( function() {
var value = jQuery( this )[ property ]();
if ( value > max ) {
max = value;
}
});
return max;
};
jQuery.fn.maxHeight = function() {
return jQuery( this ).maxDimension( 'height' );
};
jQuery.fn.maxWidth = function() {
return jQuery( this ).maxDimension( 'width' );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment