我正在尝试通过从窗口大小中减去页眉和页脚的值,并在文档加载时将内容设置为此值,动态设置网页内容的高度。
每个函数参数都接受一个元素id,以便获取元素高度;不包括内容参数。
function setH(header, content, footer)
{
winH = top.innerHeight;
winTitle = 32; // height value of the window title (part of the header)
headH = $(header).outerHeight(true);
footH = $(footer).outerHeight(true);
contentH = winH - winTitle - headH - footH;
$(content).css({'height' : (contentH) + 'px','overflow-y' : 'scroll'});
}
我遇到的问题是outerHeight值返回错误。标题返回23px,页脚返回40px。
在FF和Chrome中检查元素时,这些值分别为25px和44px。
我尝试使用innerHeight、outerHeight和outerHeight(true),但没有得到正确的值。
您有什么建议可能出了什么问题?或者有没有其他动态设置内容高度的替代方法?我已经没有头发可以拔了,所以非常感谢任何帮助。
编辑:我正在处理iframe中的内容。以下代码:
winH = top.innerHeight
获取最顶层iframe窗口的高度值。