元素隐藏时 jQuery.outerHeight 不起作用?

发布于 2024-11-30 23:12:44 字数 124 浏览 1 评论 0原文

我试图找出元素的外部高度(包括填充),但它似乎不起作用。

我总是得到0。是因为该元素被隐藏了吗?

该元素包含在具有“自动”高度的绝对定位元素内,但我认为这不应该是一个问题,因为该元素是相对的......

I'm trying to find out the outer height of a element (including padding) and it doesn't seem to work.

I always get 0. Is it because the element is hidden?

The element is contained inside a absolute-positioned element with "auto" height, but I don't think that should be a issue, because the element is relative...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪操控生活 2024-12-07 23:12:44

隐藏元素具有外部高度,

<div id="aaa" style="visibility:hidden">aaa</div>
<div id="bbb" style="visibility:hidden"></div>

alert($("#aaa").outerHeight());// returns 20

alert($("#bbb").outerHeight()); //returns 0

请添加您的 html 代码以获得更完整的答案

a hidden element has an outer height,

<div id="aaa" style="visibility:hidden">aaa</div>
<div id="bbb" style="visibility:hidden"></div>

alert($("#aaa").outerHeight());// returns 20

alert($("#bbb").outerHeight()); //returns 0

please add your html code for a more complete answer

淡淡離愁欲言轉身 2024-12-07 23:12:44

具有 display: none; 的隐藏元素不会注册高度或宽度,但具有 visibility: hide; 的元素会注册高度或宽度,但它还必须附加到 < code>body 或其子元素之一。

An element with hidden with a display: none; does not register height or width, but an element with visibility: hidden; does, but it also must be attached to the body or one of its children elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文