等效于 offsetHeight 的 jQuery 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34079032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:59:08  来源:igfitidea点击:

What is the jQuery equivalent to offsetHeight?

jquery

提问by Pota Onasys

What is the jQuery equivalent of offsetHeightin JavaScript?

offsetHeightJavaScript 中的 jQuery 等价物是什么?

I want to translate the following code to use JQuery

我想翻译下面的代码来使用JQuery

document.querySelector('.site-header').offsetHeight;

回答by Josh Crozier

The offsetHeightpropertyincludes the vertical padding and borders in the height calculation, therefore the .outerHeight()methodwould be the jQuery equivalent.

offsetHeight属性在高度计算中包括垂直填充和边框,因此该.outerHeight()方法将与 jQuery 等效。

Example Here

示例在这里

$('.site-header').outerHeight();

As a side note, the .outerHeight()methodtakes an optional parameter to include the vertical margin(s) in the height calculation:

作为旁注,该.outerHeight()方法采用可选参数以在高度计算中包含垂直边距:

$('.site-header').outerHeight(true); // With vertical margins included.