简体   繁体   English

为什么窗口不能调整到正确的高度?

[英]Why doesn't the window resize to the correct height?

I want to resize my safari browser window to match the height of a div with id 'po'. 我想调整野生动物园浏览器窗口的大小,以匹配ID为'po'的div的高度。 I have the following javascript: 我有以下javascript:

    var divHeight = document.getElementById('po').offsetHeight;
    console.log(divHeight);
    divHeight = divHeight + 30;
    var y = parseInt(divHeight,10);
    var w=window.innerWidth;
    window.resizeTo(w,y);
    console.log(divHeight);

The output of the console is: 控制台的输出为:

83
113

But the window gets resized to an actual inner height of only 30! 但是,窗口的大小调整为实际的内部高度只有30! Why isn't the window resizing correctly? 窗口为什么不能正确调整大小? If I measure the div (it contains a table), the height of the div is indeed 83. So why won't the window size match? 如果我测量div(它包含一个表),则div的高度确实为83。那么为什么窗口大小不匹配? How to fix it? 如何解决?

The problem was in my calculation and misunderstanding how window.resizeTo() works. 问题出在我的计算中,并且误解了window.resizeTo()的工作方式。

The size that window.resizeTo() sizes to includes the chrome(scrollbars, address bar,favourites bar, etc)! window.resizeTo()调整为包括chrome(滚动条,地址栏,收藏夹栏等)的大小! Once I added some "padding" to include that, it worked as expected. 一旦添加了一些“填充”以使其包含在内,它就会按预期工作。

Guessing this link will help you. 猜测此链接将对您有所帮助。 why dont you have a look at this page.... Javascript's `window.resizeTo` isn't working 你为什么不看看这个页面呢?... Javascript的“ window.resizeTo”不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM