我正在尝试监听浏览器reflow-events,以了解代码的哪些部分是最耗费资源的。当需要(重新)绘制到屏幕上时,例如在DOM中添加新元素时,会发生回流。
是否有一种方法可以监听这些事件,例如使用Javascript进行进一步分析?
是否有一种方法可以监听这些事件,例如使用Javascript进行进一步分析?
// select the target node
var target = document.querySelector('#some-id');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
observer.disconnect();