jQuery outsideHeight没有返回正确的值 [英] jQuery outerHeight is not returning the correct value

查看:80
本文介绍了jQuery outsideHeight没有返回正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过从窗口大小中减去页眉和页脚值,然后在文档加载时将内容设置为此值来动态设置网页内容的高度.

I am trying to dynamically set the height of the webpage content by subtracting the header and footer values from the window size and setting the content to this value on document load.

每个功能参数都使用一个元素ID来获取元素的高度;排除content参数.

Each of the functions parameters takes in an element id in order to grab the element height; excluding the content parameter.

 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.

The issue that I am running into is the outerHeight values are returning the wrong values. The header returns 23px and footer 40px.

当检查FF和Chrome中的元素时,值分别为25px和44px.

When examining the elements in FF and Chrome the values are 25px and 44px.

我尝试使用innerHeight,outerHeight和externalHeight(true),但没有获得正确的值.

I have tried using innerHeight,, outerHeight and outerHeight(true) but not getting the correct values.

关于可能出了什么问题的任何建议?还是动态设置内容高度的另一种方法?我的头发快要拉扯了,所以不胜感激.

Any suggestions on what might be going wrong? or an alternative way to setting the height of the content dynamically? I'm running out of hair to pull so any help is appreciated.

我正在使用iframe中的内容.以下内容:winH = top.innerHeight正在获取最顶部iframe窗口的高度值.

I am working with content in iframes. The following: winH = top.innerHeight is getting the height value of the top most iframe window.

推荐答案

要尝试帮助我的一件事是将检查outerHeight()的代码放在$(window).load()中而不是$(document).ready()中.显然,在许多情况下,使用$(document.ready()很好,但是有时outerHeight()的不正确值是由元素未完全加载引起的.

One thing to try which helped me is to put the code that checks outerHeight() in $(window).load() and not $(document).ready(). Obviously in many cases it's fine to use $(document.ready(), but sometimes the incorrect value of outerHeight() is caused from elements not being completely loaded.

这篇关于jQuery outsideHeight没有返回正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆