Skip to content

Instantly share code, notes, and snippets.

@marcbacon
Last active August 19, 2018 22:12
Show Gist options
  • Select an option

  • Save marcbacon/eff3015fe96582806da5 to your computer and use it in GitHub Desktop.

Select an option

Save marcbacon/eff3015fe96582806da5 to your computer and use it in GitHub Desktop.
jQuery function to set all Bootstrap Carousel items to the same height.
@GorgonzolaDreams
Copy link

This didn't quite work for me because the outerHeight() reads as 0 since display:none is on a parent item. If you add class "active" to the inactive ones, then measure height, then remove active from the ones you added it to (not the first one, which is supposed to be active) it works. Your way only works if the first item has the largest height.

So this goes into the first loop:

if (jQuery(this).css("display") == 'block') {
	was_show = 1;
} else {
	jQuery(this).addClass("active");
	var was_show = 0;
}

window.heights.push(jQuery(this).outerHeight());
			
if (was_show == 0) {
	jQuery(this).removeClass("active");
}

Cheers, thanks for the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment