简而言之,我希望在注入(inject) html 并呈现该 html 的内容后触发回调。原因是我需要立即知道新内容的高度。像这样:
$('div').html(tonsofstuff);
console.log( $('div').height() ); //works in Firefox, but returns 0 in Chrome
setTimeout(function(){
console.log( $('div').height() ); //works everywhere, but takes too long
},3000);
这个问题偶尔会出现在某些浏览器中(并且总是在 chrome 中)$('div').height() 在新内容具有高度之前触发。
我的幻想:
$('div').html(tonsofstuff, function(){
console.log( $('div').height() );
});
or even
$('div').html(tonsofstuff).load(function(){
console.log( $('div').height() );
});
最佳答案
这是我的做法:
var height = $('div').html(tonsofstuff).height();
我在等待它渲染时从未遇到过任何问题。
关于javascript - jQuery.html( something ) 检测注入(inject)何时完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8945957/