简体   繁体   English

使div动画但保持高度动态

[英]Animate div but keep height dynamic

I have the following scenario on JSFiddle: http://jsfiddle.net/psax3fge/ 我在JSFiddle上有以下情形: http : //jsfiddle.net/psax3fge/

D FIDDLE: http://jsfiddle.net/psax3fge/1/ D FIDDLE: http : //jsfiddle.net/psax3fge/1/

Basically its a div that has some info in it. 基本上是一个div ,其中包含一些信息。 The info is 3 separate divs that are inline block , they will be next to each other if there is enough room but will stack underneath each other when the Windows is made smaller 信息是3个单独的divs ,它们是inline block ,如果有足够的空间,它们将彼此相邻,但是当Windows变divs ,它们将彼此堆叠

I want this div to be hidden until a button is clicked where the div slides down. 我希望此div hidden直到单击div向下滑动的按钮。 I know not setting the height property will make the div have a fluid height (height gets bigger as things stack underneath each other). 我知道不设置height属性将使div具有可变的高度(随着事物在彼此下方堆叠,高度会变大)。 However, when I animate it with jQuery, I have to set a height. 但是,当我使用jQuery动画时,必须设置高度。

Is there a way to do this without losing the fluidity of the div? 有办法做到这一点而又不会失去股利的流动性吗? An alternative is to not animate the div and just make it visible/hidden on button click, but I'd really like to use the animation 另一种选择是不为div设置动画,而仅在单击按钮时使其可见/隐藏,但我真的很想使用动画

Update 4: http://jsfiddle.net/psax3fge/4/ 更新4: http//jsfiddle.net/psax3fge/4/

Leave the .container div height to auto and remove the overflow from it. 保留.container div高度为auto并从中清除溢出。
Now you can use the slideToggle function of the jQuery to show and hide the .container . 现在,您可以使用jQuery的slideToggle函数显示和隐藏.container
PS you can set display:none to container in initialization. PS可以在初始化时将display:none设置为container

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

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