animating an element's height using jquery

前端 未结 7 495
情书的邮戳
情书的邮戳 2021-01-26 04:56

I have some bars that are filled with a height %, but right when the page loads I would like all the bars to fill up and then decrease to 0. I know how to fill it up with a for

7条回答
  •  时光说笑
    2021-01-26 05:41

    You're looking for:

    for(i = 100; i >= 0; i--)
    

    But you could just do this slideUp:

    $('someElement')
        .hide()
        .slideDown(500, function () {
            $(this).slideUp(500);
        });
    

    The above would animate the element like you want. That code equates to roughly the following, in case you even want to do more complicated animate animations:

    $('someElement')
       .hide()
       .animate({ height: '100%' }, 500, function () {
            $(this).animate({ height: 0 }, 500);
        });
    

    Update: Here is a jsFiddle demonstration.

提交回复
热议问题