Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有带有“标签”的页面 - 如果您打开所有内容,它们会很长,但是当标签被激活时,页面会短很多。
现在我需要准确计算包装器 div 的高度(包含所有这些元素),但它会在所有内容可见时报告该值,因此会导致错误值..
如果您的元素display:none在 css 中,浏览器根本不会费心渲染它。在这种情况下,答案不是直接的。在最近的 jQueries 中,您甚至无法获得它的宽度或高度。
display:none
您可以获得元素的坐标,visibility:hidden但display:none元素被排除在渲染树之外。所以它的位置是不确定的。
visibility:hidden