jQuery - animate / slide to height: 100%

Mike picture Mike · Aug 12, 2009 · Viewed 35.5k times · Source

I have a siple code here:

$('.aktualita_sipky').toggle(function() {
    $(this).parent().find('.aktualita_content').animate({ 
        height: "100%",
      }, 1500 );
}, function() {
    $(this).parent().find('.aktualita_content').animate({ 
        height: "120px",
      }, 1500 );
});

Now when I click it as the first 'toggle', it just shows instantly (without the animation), when I click the the second 'toggle', it nicely slides up.

Is there a way to slide it down to 100% with that nice animation?

Answer

karim79 picture karim79 · Aug 12, 2009

Maybe you could do something like:

$height = $(window).height();   // returns height of browser viewport
//Or
$height = $(document).height(); // returns height of HTML document
//Or
$height = $(whatever).height();
$('.aktualita_sipky').toggle(function() {
    $(this).parent().find('.aktualita_content').animate({ 
        height: $height + 'px',
      }, 1500 );
}, function() {
    $(this).parent().find('.aktualita_content').animate({ 
        height: $height + 'px',
      }, 1500 );
});

http://docs.jquery.com/CSS/height