【问题标题】:jQuery - dynamic div height equal to the height of the whole windowjQuery - 动态 div 高度等于整个窗口的高度
【发布时间】:2010-12-07 17:17:57
【问题描述】:

我正在使用这里找到的代码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>

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

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

回答 使用文档而不是窗口

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

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

【问题讨论】:

    标签: jquery css html resize height


    【解决方案1】:

    你可以使用:

    $("body").height();
    

    【讨论】:

    • 谢谢,我现在明白了,我只是在编程,所以我真的不知道要改变什么,谢谢
    【解决方案2】:

    也许:

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

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

    【讨论】:

    • 分离?哦,我知道我应该使用文档而不是窗口?
    • 让我修复我的代码,看看是否可行,但我想我只需要使用文档而不是窗口谢谢
    • 你应该使用"body"选择器!
    猜你喜欢
    • 1970-01-01
    • 2017-05-11
    • 2011-12-29
    • 2013-06-06
    • 2018-03-03
    • 1970-01-01
    • 2010-11-29
    • 2011-11-23
    相关资源
    最近更新 更多