jQuery Cycle plugin - Automatic height for containers

Alex picture Alex · Jul 8, 2010 · Viewed 15.7k times · Source

I'm using the cycle plugin on some divs, like this:

<div class="sections">
  <div class="Section"> <img /> text </div>
  <div class="Section"> <img /> text </div>
  <div class="Section"> <img /> text </div>
</div>

all the .section divs have variable height, based on their contents. How can I make cycle not to resize the container div (sections) to the largest child height? Instead I want the container to resize on every animation to the current child height.

Answer

Alex picture Alex · Jul 8, 2010

ok, I managed to do it by hooking a function on 'after' event:

function onAfter(curr, next, opts, fwd) {
  var $ht = $(this).height();

  //set the container's height to that of the current slide
  $(this).parent().animate({height: $ht});
}

found the info here: http://forum.jquery.com/topic/jquery-cycle-auto-height