jQuery - 动态 div 高度等于整个窗口的高度
Posted
技术标签:
【中文标题】jQuery - 动态 div 高度等于整个窗口的高度【英文标题】:jQuery - dynamic div height equal to the height of the whole window 【发布时间】: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>
【问题讨论】:
【参考方案1】:你可以使用:
$("body").height();
【讨论】:
谢谢,我现在明白了,我只是在编程,所以我真的不知道要改变什么,谢谢【参考方案2】:也许:
$(document).height()/width()
是你需要的吗?由于窗口包含文档,并且窗口具有固定宽度并限制您从文档中查看的内容。
【讨论】:
分离?哦,我知道我应该使用文档而不是窗口? 让我修复我的代码,看看是否可行,但我想我只需要使用文档而不是窗口谢谢 你应该使用"body"
选择器!以上是关于jQuery - 动态 div 高度等于整个窗口的高度的主要内容,如果未能解决你的问题,请参考以下文章