本文介绍了当使用Jquery更改css属性时检测事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法检测一个元素的displaycss属性是否发生了变化(无论是否为block或inline-block ...)?如果没有,任何插件?谢谢解决方案
是的,您可以。 DOM L2 Events模块定义了替换为 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属性时检测事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!