简体   繁体   English

jQuery动画div大小

[英]jQuery animate div size

I have a div with hidden visibility, and I'm putting text in to that div from database so don't know it's height. 我有一个具有隐藏可见性的div,并且我正在将文本从数据库放入该div中,所以不知道它的高度。

What I would like to do is make an animation which would increase that div's size until all text is visible. 我想做的是制作一个动画,该动画将增加div的大小,直到所有文本都可见。 What I have so far is this: 我到目前为止所拥有的是:

function display_form () {
    $("#form_container").css("visibility", 'visible');
    $("#form_container").animate({
        height: $("#form_container").height(),
    }, 1500);
}
<div id="container">
    <div id="form_container"><?php echo $form; ?></div>
    <div id="content">
        some stuff here which should slide down as the form_container div gets bigger
    </div>
</div>

So my problem is that my form_container is hidden, but its size remains, so I have huge empty space. 所以我的问题是我的form_container是隐藏的,但是它的大小保持不变,所以我有巨大的空白空间。 If I set its size to 0px then I have no way of knowing its real size... 如果我将其大小设置为0px,则无法得知其实际大小...

I don't think you need to mess with the visible CSS property. 我认为您不需要弄乱visible CSS属性。

Just do something like this in your CSS: 只需在CSS中执行以下操作即可:

#form_container { display: none; }

Then your display_form function can just do this: 然后,您的display_form函数可以执行以下操作:

function display_form() {
    $('#form_container').slideDown(1500);
}

Have a look at the jQuery's slideDown . 看一下jQuery的slideDown Then you don't have to worry about the height on your own. 然后,您不必担心自己的身高。

Not sure how you are getting text from the database but if you initial have the div hidden, then place the text in the div, then you can simple use the slideDown(1000) function on that div like so: $('#mydiv').slideDown(1000); 不确定如何从数据库中获取文本,但是如果最初是将div隐藏起来,然后将文本放在div中,则可以像下面这样简单地在div上使用slideDown(1000)函数:$('#mydiv' ).slideDown(1000); The div will slide down until all the content is shown. div将向下滑动,直到显示所有内容。

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

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