0

我将两个元素之一设置为最大高度。我正在检查窗口、侧边栏和#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);
        }

}
4

3 回答 3

1

请尝试 $(document).height();获取窗口高度的代码。

于 2012-12-03T11:32:43.113 回答
0

我认为您应该使用 $(window) 或 $(document) 而不是 $(html)

于 2012-12-03T11:31:04.127 回答
0

You can use $(document).height(); but keep in mind that with no doctype tag to your page chome reports the same value for both calls ($(window) and $(document)). Adding a strict doctype causes the values to work as advertised. But you can also use $(body).height();

于 2012-12-03T11:36:59.580 回答