Delay rendering of dom element when changing properties

前端 未结 4 1493
無奈伤痛
無奈伤痛 2021-01-05 05:46

I\'ve currently run into a performance problem when updating properties on lots of dom elements at once. It seems that each time I change a property the dom element gets re-

4条回答
  •  长发绾君心
    2021-01-05 06:47

    To avoid the flash you could replace the parent with a clone of itself and then work on the original parent outside of the document. Then, when you're done, you could replace the clone with the original:

    var parent = /* define parent here */;
    var clone = parent.cloneNode(true);
    
    parent.parentNode.replaceChild(clone, parent);
    
    /* Do stuff with parent and its childNodes... */
    
    clone.parentNode.replaceChild(parent, clone);
    

提交回复
热议问题