Created
November 22, 2013 13:46
-
-
Save mikedugan/7600075 to your computer and use it in GitHub Desktop.
slices up HTML elements into equal 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
| //slices up the given items in groups of size n | |
| function sliceItems(items, n) { | |
| for(i=0; i <= items.length; i+=n) { | |
| setItems(items.slice(i,i+n)); | |
| } | |
| } | |
| //gets the max height and sets all items in a slice to that height | |
| function setItems(items) { | |
| var maxHeight = Math.max.apply(null, items.map(function() | |
| { | |
| return $(this).height(); | |
| }).get()); | |
| items.map(function() { | |
| maxHeight = Math.round(maxHeight); | |
| items.css("height", maxHeight + "px"); | |
| }) | |
| } | |
| //now use it like this to set equal heights for each group of 3: | |
| sliceItems($('.someEl'),3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment