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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1583896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:47:19  来源:igfitidea点击:

jQuery - dynamic div height equal to the height of the whole window

jquerycsshtmlresizeheight

提问by vache

i am using the code found here jQuery - dynamic div height

我正在使用此处找到的代码jQuery - 动态 div 高度

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

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

now the height change works fine when you resize the window, but if your scroll down the height does not change, this means the window property does not include things beyond the size of the browser window so if you scroll down the height does not increase

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

so what can i add that will be the size of the whole content not the window size

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

ANSWER use document instead of window

ANSWER 使用文档而不是窗口

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

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

采纳答案by meder omuraliev

Perhaps:

也许:

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

Is what you need? Since the window contains the document and the window has a fixed width and restricts what you're viewing from the document.

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

回答by Technowise

You could use:

你可以使用:

$("body").height();