如何将元素的高度复制到另一个元素?

时间:2013-04-07 13:37:57

标签: jquery jquery-animate outerheight

我有一个只有填充的div,我有另一个没有任何css属性的div。
我想使用outerHeight给两个div赋予相同的高度。

这是我的测试,这可行但不完美: http://jsfiddle.net/A2bNm/6/

$("#container").mouseenter(function () {
        $("#top").animate({ 'padding' : 70 }, "slow");
        $("#bottom").animate({'height':($("#top").outerHeight())}, "slow");

    }).mouseleave(function () {
        $("#top").animate({ 'padding' : 20}, "slow");
        $("#bottom").animate({'height':($("#top").outerHeight())}, "slow");
});

可以帮忙吗?谢谢你,抱歉我的英文不好! :)

1 个答案:

答案 0 :(得分:1)

尝试使用当前名称this和另一个名称.closest('div).siblings('div')来引用您的div。

http://api.jquery.com/siblings/ http://api.jquery.com/closest/

此外,可能将所需高度存储为自变量,因此它不是基于#top的当前值(更改)。

相关问题