如何根据浏览器的窗口大小调整HTML文档大小?

时间:2015-07-28 14:53:34

标签: javascript

我的情况:我正在将一个巨大的图像加载到我的网络应用程序中,浏览器正在调整图像的大小。然后我重新调整图像大小以适应浏览器的窗口大小,但我仍然可以向下滚动,并且有很多空白空间,因为文档没有调整其大小适应新的重新调整大小的图像。

我正在尝试做这样的事情,但它不会起作用:

var windowWidth = $(window).width();  // returns width of browser viewport
var windowHeight =$(window).height();   // returns height of browser viewport
var documentWidth = $(document).width(); // returns height of HTML document
var documentHeight = $(document).height(); // returns width of HTML document

documentWidth.resizeTo(windowWidth);
documentHeight.resizeTo(windowHeight);

1 个答案:

答案 0 :(得分:0)

var windowWidth = $(window).width();  // returns width of browser viewport
var windowHeight =$(window).height();   // returns height of browser viewport
var documentWidth = $(document).width(windowWidth); // sets height of HTML document
var documentHeight = $(document).height(windowHeight); // sets width of HTML document

您需要将文档的大小设置为窗口的大小。

resizeTo()也不是数字的属性,它不会按照您的想法执行。

相关问题