我通过 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();
}
最佳答案
编辑:这里有一个 fiddle ,其中包含加载(模拟)内容的容器(或其他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>');
});
关于javascript - 动态加载内容后 jQuery 动画 div 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19838237/