当使用Jquery更改css属性时检测事件 [英] Event detect when css property changed using Jquery
问题描述
是的,您可以。 DOM L2 Events模块定义了突变事件一>;其中之一 - DOMAttrModified 是您需要的。当然,这些并没有得到广泛的实施,但至少在Gecko和Opera浏览器中得到了支持。
尝试一下这些内容:
document.documentElement.addEventListener('DOMAttrModified',function(e){
if(e.attrName ==='style'){
console.log('prevValue:'+ e.prevValue,'newValue:'+ e.newValue);
}
},false);
document.documentElement.style.display ='block';
您也可以尝试使用 IE的propertychange事件替换为 DOMAttrModified
。它应该允许可靠地检测 style
更改。
Is there a way to detect if the "display" css property of an element is changed (to whether none or block or inline-block...)? if not, any plugin? Thanks
Yes you can. DOM L2 Events module defines mutation events; one of them - DOMAttrModified is the one you need. Granted, these are not widely implemented, but are supported in at least Gecko and Opera browsers.
Try something along these lines:
document.documentElement.addEventListener('DOMAttrModified', function(e){
if (e.attrName === 'style') {
console.log('prevValue: ' + e.prevValue, 'newValue: ' + e.newValue);
}
}, false);
document.documentElement.style.display = 'block';
You can also try utilizing IE's "propertychange" event as a replacement to DOMAttrModified
. It should allow to detect style
changes reliably.
这篇关于当使用Jquery更改css属性时检测事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!