当使用Jquery更改css属性时检测事件 [英] Event detect when css property changed using Jquery

查看:57
本文介绍了当使用Jquery更改css属性时检测事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测一个元素的displaycss属性是否发生了变化(无论是否为block或inline-block ...)?如果没有,任何插件?谢谢

解决方案

是的,您可以。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆