0

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

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

1 Answer 1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.