Forcing a DOM refresh in Internet explorer after javascript dom manipulation

前端 未结 6 1073
感情败类
感情败类 2020-11-27 18:07

Here is the situation. I have some javascript that looks like this:

function onSubmit() {
    doSomeStuff();
    someSpan.style.display=\"block\";
    otherS         


        
6条回答
  •  被撕碎了的回忆
    2020-11-27 18:45

    Mozilla (maybe IE as well) will cache/delay executing changes to the DOM which affect display, so that it can calculate all the changes at once instead of repeatedly after each and every statement.

    To force an update (to force an immediate, synchronous reflow or relayout), your javascript should read a property that's affected by the change, e.g. the location of someSpan and otherSpan.

    (This Mozilla implementation detail is mentioned in the video Faster HTML and CSS: Layout Engine Internals for Web Developers.)

提交回复
热议问题