vac*_*che 7 html css jquery height resize
我正在使用这里找到的代码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>
Run Code Online (Sandbox Code Playgroud)
现在,当您调整窗口大小时,高度更改工作正常,但如果向下滚动高度不会改变,这意味着窗口属性不包括超出浏览器窗口大小的内容,因此如果向下滚动高度不会增加
所以我可以添加的是整个内容的大小而不是窗口大小
答案使用文档而不是窗口
<script type='text/javascript'>
$(function(){
$('#center').css({'height':(($(document).height())-162)+'px'});
$(window).resize(function(){
$('#center').css({'height':(($(document).height())-162)+'px'});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
也许:
$(document).height()/width()
Run Code Online (Sandbox Code Playgroud)
是你需要的吗?由于窗口包含文档,并且窗口具有固定宽度并限制您从文档中查看的内容。