我将两个元素之一设置为最大高度。我正在检查窗口、侧边栏和#primary 容器的高度,并确保最大的那个是我设置的所有元素的高度。但是,在此页面上,与选择按钮交互时,会加载 ajax。然后我的页面高度增加。我希望我的函数能够获取新的高度,但它仍然返回旧的高度 pre-ajax 负载。
我的代码如下:
//on change of the select button load ajax content, then run changeSidebarHeight()
$('#choose-pathway').change(function() {
var url=$(this).val();
$('#ajax-pathway-container').load(url + ' #pathway',changeSidebarHeight);
});
function changeSidebarHeight(){
var primaryHeight=$('#primary').height();
var sidebarHeight=$('#sidebar').height();
var windowHeight=$(window).height();
//this always returns the same value, before the ajax load and after, despite the page being about 600 pixels taller
console.log($('html').height());
if(primaryHeight > sidebarHeight){
$('#sidebar').height(primaryHeight );
}else{
$('#sidebar').height(windowHeight );
$('#primary').height(windowHeight);
}
}