330 Locust Dr.
Verona, WI 53593
Powderkeg Web Design
Message Us

Web Dev Tid Bit (WDTB): Bootstrap Carousel Animated Height

September 05, 2017

The Bootstrap framework has a neat little carousel built in to it that I find myself using on almost every new website one form or another. The markup is pretty clean and it’s relatively easy to manipulate for customization. There is, however, 1 thing about it that I never really liked: If you have slides that are different heights and they are NOT in a fixed height container you will end up with a jumpy transition as the container expands or shrinks to the size of the new slide. Imagine the first slide below is on the screen and you slide a much shorter one. The overall height of the container is going to shrink causing the content jump suddenly:


Adding a specific container height and making sure the content always fits that is one way to do things, but that’s not a very good solution across the board. It turns out Bootstrap Carousel has some built in Javascript events that are triggered during and after slides that you can hook in to in order to animate this height change. Simple add this javascript snippet to your site:

This finds the next slide as the carousel is in the sliding transition, calculates the height of it, and uses the jQuery animate() function to give it a nice and smooth animation.

Here’s a link to a Codepen example.

Senior Developer

Nick is an ambitious and versatile developer with a wide range of talents. He is an efficient coder that utilizes his resources in order to achieve both his and the clients’ goals. His Alma Mater is the University of Wisconsin – Stevens Point where he graduated with honors in Web and Digital Media Development.