Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Created November 22, 2013 13:46
Show Gist options
  • Save mikedugan/7600075 to your computer and use it in GitHub Desktop.
Save mikedugan/7600075 to your computer and use it in GitHub Desktop.
slices up HTML elements into equal height
//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