0

div.height()$(window).resize处理程序中变得不正确。

伪代码:

var div = $('#someDiv');

div.html('');
div.css("height", "auto");

div.append( '<img src="1.jpg" style="float:left;" height="100" width="100"></img>' );
div.append( '<img src="2.jpg" style="float:left;" height="100" width="100"></img>' );
div.append( '<img src="3.jpg" style="float:left;" height="100" width="100"></img>' );
div.append( '<img src="4.jpg" style="float:left;" height="100" width="100"></img>' );
...

// I am loading the next after previous is loaded (onload)
// after last image is loaded:
console.log( div.height() );  // height is correct


$(window).resize( function(){
   console.log( div.height() );  // height is incorrect
});

在我得到它之前,DOM 是否有可能没有更新 div 的高度?

如果答案是肯定的,是否有一些我可以听的事件?

//编辑

非常感谢 @adeneo 的 jsfiddle。

我添加了调整大小处理程序,它看起来在我的桌面 chrome 中运行良好。

http://jsfiddle.net/eUUrh/2/

4

0 回答 0