简体   繁体   English

JavaScript:是否存在元素几何更改事件?

[英]JavaScript: Is there an element geometry changed event?

There is a resize DOM event, even for generic elements but I can't find a event that is fired when the position of an element changed. 即使对于通用元素,也有一个调整大小的DOM事件,但是当元素的位置更改时,我找不到触发的事件。 I'd like to have an event that is fired whenever the geometry of an element is changed. 我希望有一个事件,只要元素的几何形状发生更改,就会触发该事件。 It can be Mozilla specific, because I write a Firefox Add-On. 它可能是Mozilla特定的,因为我编写了Firefox附加组件。

Edit: Or is there a way to pin an element to another one that always works, no matter what crazy stylesheets might be used (so one is always on top of the other)? 编辑:还是有一种方法可以将元素固定到始终有效的另一个元素,而不管可能使用了哪种疯狂的样式表(因此,一个总是位于另一个之上)?

Edit: Or is there a way to pin an element to another one that always works, no matter what crazy stylesheets might be used (so one is always on top of the other)? 编辑:还是有一种方法可以将元素固定到始终有效的另一个元素,而不管可能使用了哪种疯狂的样式表(因此,一个元素始终位于另一个元素之上)?

you can set a bunch of !important rules, which take priority (unless someone else uses !important , which is rare): 您可以设置一堆!important规则,这些规则具有优先级(除非其他人使用!important ,这很少见):

.pinned {
    position : absolute !important;
    top      : 0px      !important;
    right    : 0px      !important;
    bottom   : 0px      !important;
    left     : 0px      !important;
}

DOMSubTreeModified is the closest thing around that isn't Mozilla-specific, and I don't know (or suspect) that it gets fired when geometry changes. DOMSubTreeModified是与Mozilla DOMSubTreeModified的最接近的东西,我不知道(也不怀疑)几何形状更改时会触发它。 You might be able to use DOMAttrModified and check which attrs get changed and dispatch on that, if you know which attributes will be changing, and assuming you can get CSS attributes with it. 您可能可以使用DOMAttrModified并检查要更改的attrs并对其进行调度,如果您知道要更改的属性,并假设可以获取CSS属性。 I don't think you can, but I'm not sure. 我认为您不能,但是我不确定。

https://developer.mozilla.org/en/Gecko-Specific_DOM_Events lists a MozAfterPaint event that should be able to do what you want. https://developer.mozilla.org/zh-CN/Gecko-Specific_DOM_Events列出了MozAfterPaint事件,该事件应能够执行您想要的操作。 I think. 我认为。

Good luck. 祝好运。

Edit: Wait, why do you need to do this "no matter what crazy stylesheets might be used"? 编辑:等等,为什么您需要执行此操作“无论可能使用哪种疯狂的样式表”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM