Skip to content

Instantly share code, notes, and snippets.

@GarrettWeinberg
Last active April 7, 2021 15:27
Show Gist options
  • Save GarrettWeinberg/ebda40eccae16cb4b19e14649a06e41b to your computer and use it in GitHub Desktop.
Save GarrettWeinberg/ebda40eccae16cb4b19e14649a06e41b to your computer and use it in GitHub Desktop.
Make All Cards Equal Height
// cards same height
let cards = $('.card'), //get all cards
heights = [], //height values array
tallest; //tallest card
function normalizeHeights() {
cards.each(function() {
heights.push($(this).height());
});
tallest = Math.max.apply(null, heights);
cards.each(function() {
$(this).css('min-height',tallest + 'px');
});
}
resetHeights();
$(window).on('resize orientationchange', function () {
tallest = 0, heights.length = 0;
cards.each(function() {
$(this).css('min-height','0');
});
resetHeights();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment