search

Home  >  Q&A  >  body text

Does the ResizeObserver fire first when the page loads?

It seems that when I pass the node to ResizeObserver.observe() on the DOMContentLoaded event, it is called immediately. Is this considered normal behavior?

P粉743288436P粉743288436311 days ago466

reply all(1)I'll reply

  • P粉541796322

    P粉5417963222024-03-26 20:15:17

    Yes, this behavior complies with the specification. They do have this comment:

    So, in your case, either the element isn't in the DOM yet and case 1 will make it fire, or the element is already there and case 5 will (although in "DOMContentLoaded" it should be 5 ;)< /子>.

    But according to the actual specification, observation should be triggered first no matter what. We can note that Chrome did change its behavior recently in CRBUG 1128016 as before this change they were not initially firing on hidden elements.

    reply
    0
  • Cancelreply