使用jQuery获取html元素呈现的高度 [英] Get html element rendered height with jQuery
问题描述
一个很简单的问题。
例如,我有一个这样的类:
For example, I have a class like this:
.someclass {
font-size: 1.2em /* let's say that 1em is set to 10px in this example */
padding: 1em 0 2em 0;
border: 0.1em solid #000;
}
和一些简单的html来使用它:
And some simple html to use it:
<div class="someclass">Test</div>
我想获得这个元素的生成高度 - 计算高度边框和填充。在这个例子中使用jQuery .height()
方法给出当前值 line-height
div中的文本只有一行。
I would like to get the generated height of this element - computed height with border and padding. Using jQuery .height()
method in this example gives the current value of line-height
property - as expected, because the text in the div has only one line.
我知道我可以自己做计算,因为他们相对简单,但我想问一个 - - 在jQuery中的解决方案?
I know I could do the calculations myself as they are relatively simple but I'd like to ask - is there a built-in solution for that in jQuery?
推荐答案
jQuery有几个方法来做这个。请参见 http://api.jquery.com/category/dimensions/
jQuery has several methods to do just this. See http://api.jquery.com/category/dimensions/
在这种情况下,它听起来像你想要 outerHeight()
。 http://api.jquery.com/outerHeight/
In this case, it sounds like you want outerHeight()
. http://api.jquery.com/outerHeight/
这篇关于使用jQuery获取html元素呈现的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!