简体   繁体   English

Internet Explorer 6的jQuery height()问题

[英]jQuery height() problems with Internet Explorer 6

I'm using jQuery 1.3.2. 我正在使用jQuery 1.3.2。

I'm having trouble getting a correct "height" in Internet Explorer 6. Height values are correct in all other browsers. 我无法在Internet Explorer 6中获得正确的“高度”。所有其他浏览器中的高度值都是正确的。

I am also using wresize jQuery plugin . 我也在使用wresize jQuery插件

Each time the browser loads, I fire a method that resizes divs, iframes based upon browser dimensions. 每次浏览器加载时,我都会触发一个方法,根据浏览器维度调整div,iframe的大小。 (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. 在IE 6中,$('body')。height()的返回值似乎在每次调整浏览器大小后增加10个像素。

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. 此代码用于在其父容器中设置DevExpress网格的高度。 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. 我已经尝试过窗口对象($(window).height()),但这似乎没什么帮助。

Any thoughts are appreciated! 任何想法都表示赞赏!

The problem you're facing is more likely to be a css rendering difference. 您遇到的问题更可能是css渲染差异。 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. 尝试获取$(“body”)。innerHeight()$(“body”)。outerHeight()并在不同的浏览器中比较它们,你会得到一些共同的结果。 In worst case you might need run some if cases 在最坏的情况下,你可能需要运行一些if case

Sure, here's a couple of ideas: 当然,这里有几个想法:

With IE, and esp. 用IE,特别是 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" 老IE,我喜欢在我的高度渲染功能周围添加一个1-10ms的setTimeout语句 - 它给dom和IE一个“放松”的机会

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. 尝试使用.css('height')来检索高度[它也更快]并删除'px'以获得有时更真实的测量结果。

or use a Dimensions plug in for jQuery that gives you much more to work with and it's cross browser. 或者使用Dimensions插件来获取jQuery,它可以为您提供更多工作,并且它是跨浏览器。

I use this plugin in order to draw lines from a draggable to a droppable like I show it here 我使用这个插件来绘制从可拖动到可放置的线条,就像我在这里展示的那样

$('body').height(); // call this first

iframeH = $('body').height(); //then try this

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

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