gpt4 book ai didi

javascript - CSS 属性更改监听器

转载 作者:数据小太阳 更新时间:2023-10-29 05:23:35 27 4
gpt4 key购买 nike

有任何建议的 CSS 属性更改监听器实现吗?也许:

thread =

function getValues(){
while(true){
for each CSS property{
if(properties[property] != nil && getValue(property) != properties[property]){alert('change')}
else{properties[property] = getValue(property)}
}
}
}

最佳答案

DOMAttrModified 等突变事件已弃用。考虑改用 MutationObserver。

例子:

<div>use devtools to change the <code>background-color</code> property of this node to <code>red</code></div>
<p>status...</p>

JS:

var observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.target.style.color === 'red') {
document.querySelector('p').textContent = 'success';
}
});
});

var observerConfig = {
attributes: true,
childList: false,
characterData: false,
attributeOldValue: true
};

var targetNode = document.querySelector('div');
observer.observe(targetNode, observerConfig);

关于javascript - CSS 属性更改监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12201358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com