在slidedown()之后设置元素的高度

set height on element after a slidedown()

本文关键字:元素 高度 设置 之后 slidedown      更新时间:2023-09-26

我得到了一个点击,触发了一个div上的slideDown()。我的想法是,在div扩展后,我根据扩展的div设置了另一个div的高度。问题是,它在其他div完全滑动之前获取高度并设置它,事实上,它在滑出之前获取了div的高度。

是否有办法暂停一切,直到slideDown()完成?

$div.slideDown();
//sets the height of the Container
$outer_container.css("height", $inner_container.outerHeight());

使用回调函数,该函数只在动画完成时运行:

$div.slideDown(400, function() {
    //sets the height of the Container
    $outer_container.css("height", $inner_container.outerHeight());
});

或者,使用更紧凑的方法:

$div.slideDown(400, function() {
    $outer_container.height($inner_container.outerHeight());
});