jQuery - 动态div高度等于整个窗口的高度

时间:2009-10-18 03:16:53

标签: jquery css html resize height

我正在使用此处的代码jQuery - dynamic div height

<script type='text/javascript'>
$(function(){
    $('#center').css({'height':(($(window).height())-162)+'px'});

    $(window).resize(function(){
    $('#center').css({'height':(($(window).height())-162)+'px'});
    });
});
</script>

现在,当您调整窗口大小时,高度更改工作正常,但如果向下滚动高度不会改变,这意味着窗口属性不包含超出浏览器窗口大小的内容,因此如果向下滚动高度确实如此不增加

所以我可以添加的内容是整个内容的大小而不是窗口大小

ANSWER 使用文档而不是窗口

<script type='text/javascript'>
    $(function(){
        $('#center').css({'height':(($(document).height())-162)+'px'});

        $(window).resize(function(){
        $('#center').css({'height':(($(document).height())-162)+'px'});
        });
    });
</script>

2 个答案:

答案 0 :(得分:5)

您可以使用:

$("body").height();

答案 1 :(得分:2)

也许:

$(document).height()/width()

你需要什么?由于窗口包含文档,窗口具有固定宽度,并限制您从文档中查看的内容。

相关问题