How to force ie8 to repaint after adding a class to a dom element

后端 未结 6 904
旧时难觅i
旧时难觅i 2021-02-01 05:52

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?

This

6条回答
  •  悲&欢浪女
    2021-02-01 06:18

    Fire a move or resize event on it.

    var ie8 = whateverYouUseToDetectIE();
    var element = document.getElementById("my-element");
    element.className += " new-class";
    if (ie8) {
        element.fireEvent("resize");
    }
    

提交回复
热议问题