When are MutationObserver callbacks fired?

后端 未结 2 626
一向
一向 2020-12-08 09:49

I know that MutationObservers callbacks may get called sometime after the DOM change. But the question is: What is the timing of these callbacks? Do the callbacks enter the

2条回答
  •  长情又很酷
    2020-12-08 10:25

    MutationObservers are fired asynchronously but 'soon', which means they fire before other things in the queue, such as layout, paint, or triggered events.

    This ameliorates the loss of synchrony, because you don't have to worry about screen flashing or other bad things happening before your observer gets a chance to react.

    In developer notes, they talk about an 'end-of-microtask' timing model. I agree this is poorly documented.

提交回复
热议问题