类更改后重新计算jQuery中的元素高度

类更改后重新计算jQuery中的元素高度,jquery,height,css,Jquery,Height,Css,我有一个项目列表,根据一个条件,它通过document.ready上的jQuery获得一个类,该类触发CSS3列 如果列表以列形式显示,则其高度会更小。有没有办法在类更改后立即在jQuery中获得新的高度 $items.each(function(i){ var theItem = this; console.log($(theItem).height()); //extended layout if ( theCriteria ) { $(theItem).addClass('

我有一个项目列表,根据一个条件,它通过document.ready上的jQuery获得一个类,该类触发CSS3列

如果列表以列形式显示,则其高度会更小。有没有办法在类更改后立即在jQuery中获得新的高度

$items.each(function(i){

var theItem = this;

console.log($(theItem).height());

//extended layout

if ( theCriteria ) {
    $(theItem).addClass('extended'); 
    console.log('after', $(theItem).height()); }
}

上面的代码返回两次调用的初始高度。我猜我需要触发其他东西。

很多时候,dom操作直到函数闭包完成才发生

关于这个问题的一篇好文章:

最好执行
setTimeout
函数调用,而不是直接日志

而不是:

console.log('after', $(theItem).height());
试一试

将超时设置为
0
将使其在当前正在运行的函数之后尽快运行


希望这是你的问题。祝你好运。

你能不能检查一下更改类的代码中的高度?不,它不起作用。我马上就把代码发出去
setTimeout(function(){ console.log('after', $(theItem).height()); }, 0);