기본적으로 사용할 수있는 것이 없다고 생각합니다.
사용 사례에 따라 래퍼를 쉽게 만들 수 있으므로 코드에서 래퍼를 사용하고 리스너에게 변경된 사항이 있음을 알립니다.
뭔가 같은 매우 기본적인 :
function Wrapper() {
var listeners = []
return {
addListener: function(fn) {
listeners.push(fn)
},
removeListener: function(fn) {
listeners.splice(listeners.indexOf(fn), 1) // indexOf needs shim in IE<9
},
set: function(prop, val) {
prop = val
// forEach needs shim in IE<9, or you could use a plain "for" loop
listeners.forEach(call)
function call(fn) {
fn(prop, val)
})
}
}
}
이 같이 사용할 수 있습니다
var wrapper = Wrapper()
wrapper.addListener(function(prop, val) {
// When you'll change a prop, it'll get there and you'll see
// which property is changed to which value
})
// This sets the property and notifies all the listeners
wrapper.set(document.styleSheets[0].rules[0].style.backgroundImage, "url(myimage.png)")
나는 생각한다, 당신은 변수에 CSSText의를 유지하고 나중에 비교할 수 있습니다. –
@Mr_Green 문제를 해결하지 못하면서 OP는 CSS가 바뀌면 발동 할 수있는 이벤트가 있는지 묻습니다. DOM Mutation 이벤트와 동일합니다. 재미있는 질문 OP. –
큰 문자열을 폴링하는 @Mr_Green이 정확하지 않습니다 –