I have a testimonial section of a webpage that I'm developing and it will simply cycle through a number of different testimonial comments using jQuery fadeIn()
& fadeOut()
If I don't dictate the height of the section to a set height then the height will change according to the length of the testimonial comment and the rest of the page below will jump around.
As I am creating this site using Wagtail (Django based CMS) and so I want to be able to automate calculating the appropriate sized section height according to the longest testimonial comment.
Here is the code that I have so far:
HTML:
<section class="bg-primary testimonial-wrapper" id="testimonials">
<div class="container">
<div class="row">
<div class="col-xs-2 col-xs-offset-2">
<i class="fa fa-4x fa-quote-left"></i>
</div>
<div class="col-xs-6 testimonial-wrapper">
<div class="testimonial-item">
<p>Testimonial comment 1.</p>
<p><em>- Oliver Nicholson</em></p>
</div>
<div class="testimonial-item">
<p>Another quote!</p>
<p><em>- Nollie Bollie</em></p>
</div>
</div>
</div>
</div>
</section>
jQuery/JS:
$(document).ready(function() {
var testimonials = $(".testimonial-item");
testimonials.hide();
var testimonialIndex = -1;
function showNextTestimonial() {
++testimonialIndex;
testimonials.eq(testimonialIndex % testimonials.length)
.fadeIn(2000)
.delay(500)
.fadeOut(2000, showNextTestimonial);
}
showNextTestimonial();
});
Is there any way to calculate the min-height
of testimonial-wrapper
so that the testimonial-wrapper
section is able to accommodate every comment without changing size when transitioning from one comment to the next?