谷歌浏览器返回错误的窗口高度?

时间:2010-01-07 03:55:13

标签: javascript google-chrome

我一直在处理这个脚本http://www.acgunsdcroses.com/agencymeter/。似乎只有google chrome返回错误的窗口高度,因此设置div的高度错误,在红色和蓝色div之间留下一个空白区域。奇怪的是,这只发生在第一次在新窗口/选项卡中加载页面时,重新加载时工作正常。

你们可以重现这个吗?你知道我能做些什么吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

这并不能真正回答您关于Google Chrome错误的问题,但这是我针对您的具体情况的建议:

我会使用CSS而不是使用JavaScript设置页面:

示例

Example on JSBin

<强> HTML

<div id="received">27 Emails received since Wed, 06 Jan 2010 05:00:05</div>
<div id="sent">10 Emails sent since Wed, 06 Jan 2010 05:00:05</div>

<强> CSS

html, body { height: 100%; width: 100%; position: relative; margin: 0; padding: 0 }

#received, #sent { position: absolute; left: 0; width: 100%; }
#received { top: 0; bottom: 200px;  background-color: #ff0000; }
#sent     { bottom: 0; height: 200px; background-color: #0000ff; }

<强>更新

您仍然可以使用JavaScript来播放分割比例,但它总是会填满屏幕,即使计算结果与理想情况相差2或3个像素:

<强> JS

var received = document.getElementById('received'),
    sent     = document.getElementById('sent');

// Be sure to set 'sent' height to whatever you set 'received' bottom to:
received.style.bottom = "300px";
sent.style.height     = "300px";

// You should also be able to use percentages:
received.style.bottom = "30%"; // Received will occupy 70%
sent.style.height     = "30%"; // Sent will occupy 30%