2012-08-30 17 views
6

CSSプロパティー変更リスナーの推奨実装はありますか?多分: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)} 
    } 
    } 
} 

答えて

3

私はあなたがこのために探していると思う:あなたはそれをグーグル場合は、原料の束が立ち上がる

document.documentElement.addEventListener('DOMAttrModified', function(e){ 
    if (e.attrName === 'style') { 
    console.log('prevValue: ' + e.prevValue, 'newValue: ' + e.newValue); 
    } 
}, false); 

。しかしこれは有望に見える:DOMAttrModifiedよう

http://darcyclarke.me/development/detect-attribute-changes-with-jquery/

+0

この1つはWebKitをベースのブラウザ、少なくともChromeで動作しません。 –

2

変異イベントが廃止されました。代わりに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); 
関連する問題