IE7中的scrollHeight返回不正确的值,除非在使用前特别引用 [英] scrollHeight in IE7 returns incorrect value unless specifically referenced before used

查看:64
本文介绍了IE7中的scrollHeight返回不正确的值,除非在使用前特别引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个针对MooTools的手风琴类,更多地满足我的需要,但注意到在IE7(我仍然需要支持),element.scrollHeight返回一个不正确的值,除非我特别引用它之前使用它。例如,我有一个元素的类container和collapsed&以下样式从页面中隐藏:

I have been working on an Accordion class for MooTools that is more catered to what I need, but have noticed that in IE7 (which I still need to support), element.scrollHeight returns an incorrect value unless I specifically reference it before using it. For example, I have an element with the classes "container" and "collapsed" & following styles that is hidden from the page:

.container {
    overflow: hidden;
}

/* removed when made visible */
.collapsed {
    left: -9999em;
    position: absolute;
    top: 0px;
}



当我需要显示这个元素时,我删除该类, scrollHeight。在大多数浏览器,这工作正常。但是,在IE7中,下面的代码返回的高度明显小于元素的实际scrollHeight:

When I need to display this element, I remove the class, and calculate its scrollHeight. In most browsers, this works fine. However, in IE7, the following code returns a height that is significantly smaller than the element's actual scrollHeight:

// remove the collapsed class
elem.removeClass('collapsed');

alert(elem.scrollHeight); // consistently '69px' across all accordion folds

但是,如果我先引用elem.scrollHeight警告scrollHeight是正确的:

However, if I reference elem.scrollHeight first, the alerted scrollHeight is correct:

// remove the collapsed class
elem.removeClass('collapsed');

if (elem.scrollHeight) alert(elem.scrollHeight); // the scrollHeight is correct

IE7只需要额外的几毫秒来正确重新计算元素的scrollHeight,

Does IE7 just need the additional few milliseconds to properly recalculate the element's scrollHeight, or is there something else at play?

感谢您的帮助!

推荐答案

查看此表。


当元素没有滚动条时,IE使scrollHeight
等于内容的实际高度;而不是
元素的高度。 scrollWidth是正确的,除了在IE8,它的5像素
关闭。

When the element has no scrollbars IE makes the scrollHeight equal to the actual height of the content; and not the height of the element. scrollWidth is correct, except in IE8, where it’s 5 pixels off.

和scrollHeight标记为不正确 -7。
也许它将与offsetHeight工作?或从其他属性以某种方式计算?

And scrollHeight marked as 'incorrect' for ie5-7. Maybe it will work with offsetHeight? Or calculate it somehow from other properties?

这里提到...


无论你做什么,在IE访问属性不在body的onload
被触发之前,否则你会得到奇怪的结果。

Whatever you do, in IE access the propertys not before body's onload has fired, otherwise you will get weird results.

这篇关于IE7中的scrollHeight返回不正确的值,除非在使用前特别引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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