Last active
April 7, 2021 15:27
-
-
Save GarrettWeinberg/ebda40eccae16cb4b19e14649a06e41b to your computer and use it in GitHub Desktop.
Make All Cards Equal Height
This file contains 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
// 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