Skip to content

Instantly share code, notes, and snippets.

@oskarkrawczyk
Created May 19, 2009 19:07
Show Gist options
  • Save oskarkrawczyk/114323 to your computer and use it in GitHub Desktop.
Save oskarkrawczyk/114323 to your computer and use it in GitHub Desktop.
Equalize dimensions of a set of elements
/* Equalizes dimensions of selected elements.
*
* els.equalize();
*
* Example:
*
* $$('.boxes').equalize('height', 'max', 20);
* $$('.boxes').equalize('width', 'min');
* $$('.boxes').equalize('height');
*
* Author: Oskar Krawczyk (oskar dot krawczyk dot com after nouincolor)
*/
Array.implement({
equalize: function(dir, mode, offset) {
var dir = $pick(dir, 'height');
var axis = dir == 'height' ? 'y' : 'x';
maxHeight = [];
this.each(function(el) {
maxHeight.push(el.getSize()[axis]);
});
this.setStyle(dir, Math[$pick(mode, 'max')].apply(Math, maxHeight) + $pick(offset, 0));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment