简体   繁体   English

用jQuery完全扩展后如何获取div高度

[英]How to get div height after is completely expanded with jquery

I have read some documentation but I don't have this clear enough. 我已经阅读了一些文档,但还不够清楚。

Let's say I have an image that expands a huge div with class .content . 假设我有一个图像,该图像使用class .content扩展了一个巨大的div。 I'd like to know how much the <div class="content"> height, so I do this simple thing inside the function that expands the div 我想知道<div class="content">高度,所以我在扩展div的函数中做了这个简单的事情

contentSize = $('.content').outerHeight(true);
console.log('Content size is', contentSize, 'pixels');

use some console logging to see the return but the value is not right. 使用一些控制台日志记录来查看返回值,但该值不正确。 I guess because when the console returns the value the height the div is not completely expanded. 我猜是因为当控制台返回该值时,div的高度并未完全扩展。 Let's say console returns 1500px but the final height is 3000px. 假设控制台返回1500px,但最终高度为3000px。

How can I get the right height after the div is completely expanded? div完全扩展后,如何获得合适的高度?

Many thanks 非常感谢

Well, I found a way to find this. 好吧,我找到了找到此方法的方法。 I'm posting here in case someone might find it useful. 我在这里发布,以防有​​人发现它有用。

In my case, my <div.content> was nested in another <div> with class .animator so if I do this 在我的情况下,我的<div.content>被嵌套在另一个带有.animator类的<div> ,所以如果我这样做

var contentSize = $('.animator').find('.content').outerHeight(true);
console.log('Content size is', contentSize, 'pixels');

Then console log returns the right height of .content 然后控制台日志返回正确的.content高度

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM