“Offsite” copy of the DOM to do manipulations

后端 未结 1 996
礼貌的吻别
礼貌的吻别 2020-12-12 02:33

I have recently watched a video of Nicholas Zakas talk about high performace scripts. This one is about reflow and repaint. he says it\'s bad to constantly reflow which is m

相关标签:
1条回答
  • 2020-12-12 03:02

    When thinking about creating a copy of the DOM, the following methods can be useful:

    • document.createDocumentFragment() - Creates a plain "node storage" object.
    • document.implementation.createDocument and the DOMParser - Create and manipulate full document.
    • cloneNode - Copy a node (DOM manipulation using appendChild and replaceChild).

    These methods are very useful for DOM structures, but unfortunately, they do not return useful values for dimensions.

    The elements have to be rendered. This can be done by creating an <iframe> element, and insert the document (nodes) in it. The previously mentioned methods can be used for this purpose: Create an effective copy of (part of) the document, and insert the document into the iframe.

    It might be useful to also insert a <base> element in the <head>, so that URLs and images are correctly resolved.

    0 讨论(0)
提交回复
热议问题