如何在将类添加到dom元素后强制ie8重绘 [英] How to force ie8 to repaint after adding a class to a dom element
问题描述
在ie8中,如果元素在更改类名时没有与关联的css重新绘制,那么如何强制浏览器刷新而不是杀死ie8性能?
In ie8 if elements don't 'repaint' with the associated css when you change the classname, how can you force the browser to refresh and not kill ie8 performance?
这篇文章(我该怎么办?强制WebKit重绘/重绘以传播样式更改?)建议调用offsetHeight来强制重绘。
This post (How can I force WebKit to redraw/repaint to propagate style changes?) suggested calling offsetHeight which forces a repaint.
这篇文章( http://www.tek-tips.com/viewthread.cfm?qid=1688809 )有一条评论建议在body元素中添加和删除一个类。
This post (http://www.tek-tips.com/viewthread.cfm?qid=1688809) had a comment that suggested adding and removing a class from body element.
这两种方法都杀死了ie8性能,第一种方法对我的布局产生了副作用。
Both of these approaches killed ie8 performance and the first had side-effects on my layout.
最好的方法是什么?
推荐答案
我为ie8问题提出的解决方案是在我正在改变的元素的近父级上添加/删除一个类。由于我正在使用现代化器,我检查ie8,然后执行此操作添加/删除舞蹈以获取新的css进行绘制。
The solution I came up with for my ie8 issue was to add/remove a class on a near parent of the element i'm changing. Since I'm using modernizer, I check for ie8 and then do this add/remove dance to get the new css to paint.
$uicontext.addClass('new-ui-look');
if ($('html').is('.ie8')) {
// IE8: ui does not repaint when css class changes
$uicontext.parents('li').addClass('z').removeClass('z');
}
这篇关于如何在将类添加到dom元素后强制ie8重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!