简体   繁体   English

动画DIV的高度以适应动态加载的内容

[英]Animate DIV's height to fit dynamically loaded contetent

A DIV which it's content (another inner DIV ) can be changed. DIV其它的内容(另一内DIV )可以被改变。 I want to achieve the following effect: 我想要达到以下效果:

  1. Fade out current content. 淡出当前内容。

  2. Animate the height of DIV to fit the height of the new content. 对DIV的高度进行动画处理以适合新内容的高度。

  3. Fade in the new content. 淡入新内容。

See this fiddle: 看到这个小提琴:

http://jsfiddle.net/WNS3B/ http://jsfiddle.net/WNS3B/

This is made possible using jquery and a fallback function of fadeOut method. 这可以通过使用jQuery和fadeOut方法的后备功能来实现。

$('.one').fadeOut(function(){
    $('.p').css('height', oldH); // keeping parent from collapsing
    $('.p').animate({"height": newH});
    $('.two').delay(300).fadeIn();
});

You do not need to use delay . 您不需要使用delay you can use done callback on animate 您可以对animate使用完成回调

$('.p').css('height', oldH); // keeping parent from collapsing
$('.one').fadeOut(function(){
    $('.p').animate({"height": newH},{
        done: function(){
            $('.two').fadeIn();    
        }
    });

});
})

see the updated fiddle http://jsfiddle.net/WNS3B/2/ 请参阅更新的小提琴http://jsfiddle.net/WNS3B/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM