用jQuery获取绝对DIV的高度 [英] Getting height of an absolute DIV with jQuery

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

问题描述

我正在尝试使用非预定义高度属性的绝对定位DIV的 height 属性。

I am trying to the the height attribute of an absolute positioned DIV with a non predefined height attribute.

div 的高度取决于其动态内容。

The height of the div depends on its dynamic content.

我已经看到 .height() jQuery的函数没有返回绝对定位的正确高度 div

I've seen that .height() function of jQuery doesn't return the correct height of an absolute positioned div.

$(this).height()  //not working well

有没有办法获得它的高度?

Is there any way to get its height?

谢谢。

推荐答案

你需要在div中包含一些内容或至少定义一些最小高度才能获得css height属性 - 否则未定义。

You need to have some content inside the div or at least define some minimum height in order to get the css height property—which is otherwise undefined.

.height()获取元素的计算高度,因此需要一些预定义。

The .height() gets the computed height for the element and thus needs some predefining.

替代方案是 .innerHeight() .outerHeight()方法。如果您使用默认的内容框样式,它们可能会更好。

Alternatives are the .innerHeight() and .outerHeight() methods. They might work better if you are working with the default content-box style.

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

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