0

So I want to toggle this animation in jQuery but I found it very hard to find a way.

$( "#console" ).animate({height: "20px"});

1 Answers1

1

You can set height of element in variable and use it to animate. Also you need to save toggle state to having animation without bug.

var firstHeight = $("div").height();
$("div").click(function(){
    $(this).stop();
    if (!$(this).data("animateToggle"))
        $("div").data("animateToggle", 1).animate({height: "200px"});
    else       
        $("div").removeData("animateToggle").animate({height: firstHeight});
});
div {
    width: 100px;
    height: 100px;
    background: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
Mohammad
  • 21,175
  • 15
  • 55
  • 84