jQuery - 动态div高度等于整个窗口的高度 [英] jQuery - dynamic div height equal to the height of the whole window

查看:173
本文介绍了jQuery - 动态div高度等于整个窗口的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这里找到的代码 jQuery - 动态div高度

i am using the code found here 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>

现在,调整窗口大小时,高度变化可以正常工作,但如果向下滚动高度不会更改,这意味着窗口属性不包括超出浏览器窗口大小的事情,所以如果你向下滚动高度不增加

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
使用文档而不是窗口

ANSWER use document instead of window

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

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


推荐答案

也许:

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


b $ b

你需要什么?由于窗口包含文档,并且窗口具有固定的宽度,因此会限制您正在查看的文档。

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.

这篇关于jQuery - 动态div高度等于整个窗口的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆