Slide down animation from display:none to display:block?

前端 未结 5 1220
无人共我
无人共我 2020-12-14 07:47

Is there a way to animate display:none to display:block using CSS so that the hidden div slides down instead of abruptly appearing, or should I go about this a different way

5条回答
  •  温柔的废话
    2020-12-14 08:15

    I like the idea of CSS transitions, but it's still very jumpy. Sometimes the max-height has to be set to a very high number because of dynamic content which renders the transition useless as it's very jumpy. So, I went back to jQuery, but it had its own faults. inline elements are jumpy.

    I found this to work for me:

    $(this).find('.p').stop().css('display','block').hide().slideDown();
    

    The stop stops all previous transitions. The css makes sure it's treated as a block element even if it's not. The hide hides that element, but jquery will remember it as a block element. and finally the slideDown shows the element by sliding it down.

提交回复
热议问题