jQuery获取自动高度元素的高度 [英] Jquery get height of auto height element

查看:414
本文介绍了jQuery获取自动高度元素的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以返回已经设置为auto的元素的高度?当我调用$(#element").height();时,我只会得到0.

Is there any way to return the height of an element that is already set to auto? I just get 0 when I call $("#element").height();

这是jquery代码. img.height()返回0,因此最终结果为关闭状态.

Here is the jquery code. The img.height() return 0 therefore the end result is off.

img.css({top: (img.parent().height() - img.height()) /2, left: (img.parent().outerWidth() - img.outerWidth()) / 2});

HTML看起来像这样:

The HTML looks like this:

<div id="exploreImage" class="virtual-room-large" style="width: 288px; height: auto; top: 185px; left: 89px; ">

推荐答案

您尝试了 $("#element").outerHeight() ?它获取计算出的高度,而不是显式设置的高度.

Did you try $("#element").outerHeight()? It gets the computed height rather than the explicitly set height.

这篇关于jQuery获取自动高度元素的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆