【发布时间】:2016-08-17 15:24:10
【问题描述】:
我通过 javascript 更改元素的高度(无法通过 css 将其从 0 更改为 auto)。
/* 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 进行更改?
【问题讨论】:
-
为什么要把它设置为固定高度,展开时设置为
auto,折叠时设置为zero。 -
@vivekkupadhyay 我愿意吗?我坚持
autoHeight = element.css('height', 'auto').height();让它自动。
标签: javascript jquery html css jquery-animate