我通过AJAX加载页面,其内容表示为字符串。之后,如果内容大于实际容器的高度,我想要为容器的高度设置动画。但是,_height
是0.为什么?
function adjustMainContainerHeight() {
var _height = $('div.content').wrapInner('<div>').outerHeight();
$("div.main").animate({ height: _height }, 600);
}
function prepareResult(data) { //data is HTML string returned by server
$('div.content').html(data);
adjustMainContainerHeight();
}
答案 0 :(得分:1)
编辑:继承了加载(模拟)内容的容器(或其他div)的工作动画的小提琴:
function adjustMainContainerHeight(_height) {
$("div.main").animate({ height: _height }, 600);
}
function prepareResult(data) { //data is HTML string returned by server
$('div.content').html(data);
adjustMainContainerHeight($('div.content').height());
}
$(function(){
$('div.main').height(0);
prepareResult('<p>foo</p><p>bar</p><p>foo</p><p>bar</p>');
});