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

后端 未结 6 898
旧时难觅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:39

    This expands on the other answers here. You need to both add a new class (Doug's answer) and ensure the class has a different content value (Adam's answer). Changing the class alone may not be enough. The content change is needed to force IE8 to repaint. Here is a related blog post.

    Here is the JQuery to change add the new class:

    $(".my-css-class").addClass("my-css-class2");
    

    Here is CSS with the 2nd class having a slightly different content value:

    .my-css-class:before {content: "\e014";}
    .my-css-class2:before {content: "\e014 ";}
    

提交回复
热议问题