Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 17, 2023 18:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/5bb764b356e5c30d75b6dd20a214dddf to your computer and use it in GitHub Desktop.
Save zackpyle/5bb764b356e5c30d75b6dd20a214dddf to your computer and use it in GitHub Desktop.
Set equal heights using jQuery
jQuery(document).ready(function($) {
$.fn.equalHeights = function() {
let max_height = 0;
$(this).each(function() {
max_height = Math.max($(this).height(), max_height);
});
$(this).each(function() {
$(this).height(max_height);
});
};
// Equal Heights on All Screen Sizes
$(".fl-heading").equalHeights();
// Recheck equal height on screen size change
$(window).resize(function() {
setTimeout(function() {
$(".fl-heading").css('height', 'auto');
$(".fl-heading").equalHeights();
}, 500);
});
// Only Mobile - Useful when things are stacked so equal heights don't matter anymore
if ($(window).width() > 768) {
const ppInfoboxDescriptions = $(".pp-infobox-description");
ppInfoboxDescriptions.equalHeights();
$(window).resize(function() {
setTimeout(function() {
ppInfoboxDescriptions.css('height', 'auto');
ppInfoboxDescriptions.equalHeights();
}, 500);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment