Jquery 在调整窗口大小时获取文档的大小

Jquery 在调整窗口大小时获取文档的大小,jquery,html,Jquery,Html,当我调整窗口大小时,我可以找到窗口的大小 <script type="text/javascript"> jQuery(window).resize(function () { var width = jQuery(window).width(); var height = jQuery(window).height(); console.log(width); console.log(height); }) <

当我调整窗口大小时,我可以找到窗口的大小

<script type="text/javascript">

    jQuery(window).resize(function () {
      var width = jQuery(window).width();
      var height = jQuery(window).height();
      console.log(width);
      console.log(height);
    })
</script>

jQuery(窗口).调整大小(函数(){
var width=jQuery(window).width();
var height=jQuery(window).height();
控制台。原木(宽度);
控制台。原木(高度);
})
现在,我想在调整窗口大小时获得文档大小。如何获得每次调整窗口大小时的大小

$(窗口).width();//返回浏览器视口的宽度

$(文档).width();//返回HTML文档的宽度


您可以使用
文档
对象:

var width = jQuery(document).width();
var height = jQuery(document).height();
演示:

如您所见,当窗口较小时,文档的大小是相同的值。当窗口变得比文档所需的大时,文档将拉伸到窗口的大小

您还可以获取
document.body
元素的大小:

var width = jQuery(document.body).width();
var height = jQuery(document.body).height();

不同之处在于,即使窗口更高,也可以获得body元素的高度,即body元素不会自动延伸到窗口底部。

修改示例代码以同时获得它

<script type="text/javascript">

    jQuery(window).resize(function () {
      var width = jQuery(window).width();
      var height = jQuery(window).height();
      var documentWidth = jQuery(document).width();
      var documentHeight = jQuery(document).height();
      console.log(width);
      console.log(height);
    })
</script>

jQuery(窗口).调整大小(函数(){
var width=jQuery(window).width();
var height=jQuery(window).height();
var documentWidth=jQuery(document).width();
var documentHeight=jQuery(document).height();
控制台。原木(宽度);
控制台。原木(高度);
})

不确定是否需要:

jQuery(window).resize(function () {
   var winwidth = jQuery(window).width();
   var winheight = jQuery(window).height();
   var docwidth = jQuery(document).width();
   var docheight = jQuery(document).height();
   console.log('window width is -> ' + winwidth + 'window height is -> ' + winheight);
   console.log('document width is -> ' + docwidth + 'document height is -> ' + docheight);
}).resize();
//-^^^^^^^^----this will log everytime on doc ready

我知道$(document).width()和$(document).height()给出了HTML文档的宽度和高度,但是当窗口调整大小时,有没有办法调整HTML文档的大小。使用
百分比
em
声明内容的宽度,网站将根据窗口宽度进行缩放。