Internet Explorer 6 的 jQuery height() 问题
我正在使用 jQuery 1.3.2。
我在 Internet Explorer 6 中无法获得正确的“高度”。高度值在所有其他浏览器中都是正确的。
我还使用 wresize jQuery 插件 。
每次加载浏览器时,我都会触发一个根据浏览器尺寸调整 div、iframe 大小的方法。 (这是有充分理由的。)
在 IE 6 中,$('body').height() 的返回值似乎在浏览器每次调整大小后添加 10 个像素。
还有其他人遇到过这样的事情吗?
var iframeH = 0, h = 0, groupH = 0, adjust = 0;
var tableH = $("#" + gridId + "_DXHeaderTable").parent().height();
var pagerH = $(".dxgvPagerBottomPanel").height();
var groupHeight = $(".dxgvGroupPanel").height();
if (pagerH == null)
pagerH = 0;
if (groupHeight != null)
groupH = groupHeight + pagerH;
iframeH = $('body').height();
h = (iframeH - (tableH + pagerH + groupH));
$('#' + gridId + "Panel").css("height", (h + "px"));
$("#" + gridId + "_DXMainTable").parent().css("height", (h + "px"));
此代码用于设置 DevExpress 网格在其父容器中的高度。 忽略代码可以更好的事实。 :)
除了“body”之外,还有什么可以用来获得正确的尺寸吗? 我尝试过窗口对象($(window).height()),但这似乎没有多大帮助。
任何想法表示赞赏!
I'm using jQuery 1.3.2.
I'm having trouble getting a correct "height" in Internet Explorer 6. Height values are correct in all other browsers.
I am also using wresize jQuery plugin.
Each time the browser loads, I fire a method that resizes divs, iframes based upon browser dimensions. (There's a good reason for this.)
The returned value of $('body').height(), in IE 6, seems to add 10 pixels after each resize of the browser.
Anyone else come across something like this?
var iframeH = 0, h = 0, groupH = 0, adjust = 0;
var tableH = $("#" + gridId + "_DXHeaderTable").parent().height();
var pagerH = $(".dxgvPagerBottomPanel").height();
var groupHeight = $(".dxgvGroupPanel").height();
if (pagerH == null)
pagerH = 0;
if (groupHeight != null)
groupH = groupHeight + pagerH;
iframeH = $('body').height();
h = (iframeH - (tableH + pagerH + groupH));
$('#' + gridId + "Panel").css("height", (h + "px"));
$("#" + gridId + "_DXMainTable").parent().css("height", (h + "px"));
This code is for setting the height of a DevExpress grid in it's parent container. Ignore the fact that the code could be better. :)
Is there something other than "body" that I could use to get me a correct size? I've tried the window object ($(window).height()), but that doesn't seem to help much.
Any thoughts are appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您面临的问题更可能是 css 渲染差异。 由于浏览器之间的浮动问题、填充和边距呈现差异。
尝试获取 $("body").innerHeight() 和 $("body").outerHeight() 并在不同浏览器中比较它们,你会得到一些共同的结果。 在最坏的情况下,您可能需要运行一些
if
情况The problem you're facing is more likely to be a css rendering difference. Because of floating problems, padding, and margin rendering differences between browsers.
try to get $("body").innerHeight() and $("body").outerHeight() and compare them in different browsers, you'll get some common results. In worst case you might need run some
if
cases当然,这里有一些想法:
使用 IE,尤其是。 较旧的 IE,我喜欢在高度渲染函数周围添加 1-10 毫秒的 setTimeout 语句 - 它给 dom 和 IE 一个“放松”的机会
另外,确保你的内容在页面上可见 - 为此,你可能需要使用绝对位置暂时将某些内容从屏幕上移开,然后再次将它们显示在屏幕上。
另一件事是 height() 有时很不稳定。 尝试使用 .css('height') 检索高度 [它也更快] 并删除 'px',以获得有时更真实的测量结果。
Sure, here's a couple of ideas:
With IE, and esp. older IE, I like to add a 1-10ms setTimeout statement around my height rendering functions -- it gives the dom and IE a chance to "relax"
Also, make sure you're stuff is visible on page -- for this, you may need to throw things off the screen temporarily using absolute position, and then reveal them onscreen again.
Another thing is that height() is sometimes wonky. Try .css('height') to retrieve heights [it's also faster] and remove the 'px' for what is sometimes a truer measurement.
或者使用 jQuery 的Dimensions 插件,它可以为您提供更多的使用体验,而且它是跨浏览器的。
我使用这个插件来绘制从可拖动到可放置的线条,就像我在这里展示一样
or use a Dimensions plug in for jQuery that gives you much more to work with and it's cross browser.
I use this plugin in order to draw lines from a draggable to a droppable like I show it here