var $tar = document.querySelector('.zp-page')
var MutationObserver =
window.MutationObserver ||
window.webkitMutationObserver ||
window.MozMutationObserver
var mutationObserver = new MutationObserver((mutations) => {
// 监听到变化执行
})
mutationObserver.observe($tar, {
childList: true, // 子节点的变动(新增、删除或者更改)
attributes: true, // 属性的变动
characterData: true, // 节点内容或节点文本的变动
subtree: true, // 是否将观察器应用于该节点的所有后代节点
attributeFilter: ['class', 'style'], // 观察特定属性
attributeOldValue: true, // 观察 attributes 变动时,是否需要记录变动前的属性值
characterDataOldValue: true // 观察 characterData 变动,是否需要记录变动前的值
})

网友评论