Created
May 19, 2009 19:07
-
-
Save oskarkrawczyk/114323 to your computer and use it in GitHub Desktop.
Equalize dimensions of a set of elements
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
/* 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