动画后响应自动高度容器

时间:2016-08-17 07:18:51

标签: javascript jquery html css jquery-animate

我通过javascript更改元素的高度(无法通过css从0更改为自动)。

/* Function to animate height: auto */
function autoHeightAnimate(element, time){
    var curHeight = element.height(), // Get Default Height
        autoHeight = element.css('height', 'auto').height(); // Get Auto Height
          element.height(curHeight); // Reset to Default Height
          element.stop().animate({ height: autoHeight }, time); // Animate to Auto Height
}

在我调整Chrome窗口大小后,该元素不会自动更改其高度,因为它仅在我单击其中一个标签后才会更改。 DEMO这里。

可以通过css以某种方式做到吗?如果不是如何通过javascript / jQuery来实现它,以便在我扩展浏览器窗口后进行更改?

1 个答案:

答案 0 :(得分:0)

在这种情况下,您可以使用调整大小功能并在调整大小时设置高度,如下所示:

$( window ).resize(function() {
      autoHeightAnimate('','');
});