【发布时间】: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