Jquery获取自动高度元素的高度

bre*_*njt 13 jquery height

有没有办法返回已设置为auto的元素的高度?当我调用$("#element")时,我得到0.高度();

这是jquery代码.所述img.height()返回0因此,最终结果是关闭的.

img.css({top: (img.parent().height() - img.height()) /2, left: (img.parent().outerWidth() - img.outerWidth()) / 2});
Run Code Online (Sandbox Code Playgroud)

HTML看起来像这样:

<div id="exploreImage" class="virtual-room-large" style="width: 288px; height: auto; top: 185px; left: 89px; ">
Run Code Online (Sandbox Code Playgroud)

Gho*_*o5t -3

你试过了吗$("#element").outerHeight()?它获取计算的高度而不是显式设置的高度。

  • 如果这不起作用,为什么它是公认的答案? (12认同)