在IE7中更改DHTML后如何强制重排? [英] How can I force reflow after DHTML change in IE7?

查看:124
本文介绍了在IE7中更改DHTML后如何强制重排?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,用户可以动态添加文件上传框。添加框会改变它们所处的div的高度,但是它下面的div的某些元素保持在同一个位置,因此它们开始与新的DOM元素重叠。

I have a page where the user can dynamically add file upload boxes. Adding the boxes changes the height of the div they are in, but certain elements of the div below it stay in the same place, so they start to overlap with the new DOM elements.

这在IE8,Firefox,Chrome中正常运行。如何强制IE7使用新的DHTML重排页面?

This works correctly in IE8, Firefox, Chrome. How can I force IE7 to reflow the page with the new DHTML?

我得出的最佳解决方案是:

The best solution I worked out was this:

window.resizeBy(1, 0); 
setTimeout(UndoResize, 0);

但它不适用于最大化窗口(它会恢复窗口)。

But it doesn't work with a maximized window (it restores the window).

推荐答案

尝试:

element.className = element.className;

修改后的div(或者可能是其父级,甚至更偏远的祖先,具体取决于各种因素)比如相对定位的遏制)。

on the modified div (or possibly its parent, or even a more remote ancestor, depending on various factors such as relatively-positioned containment).

由于 className 已经分配了一个值,IE将重排并重新绘制在影响该元素的CSS发生变化的情况下,页面的一部分。幸运的是,它没有进行优化以检查 className 值是否实际上从之前的值发生了变化,因此上述内容将触发重排而不会破坏任何其他值。

As the className has been assigned a value IE will reflow and repaint that portion of the page in case the CSS affecting that element has changed. Luckily, it isn't optimised to check if the className value actually changed from its previous value, so the above will trigger the reflow without breaking anything else.

我确实找到了一次这个固定的IE6但是打破了IE7,但试试看看它是否适合你。

I did find one occasion when this fixed IE6 but broke IE7, but try it and see if it works for you.

这篇关于在IE7中更改DHTML后如何强制重排?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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