admin管理员组文章数量:1400026
When using DOMSubtreeModified
I get multiple, sometimes 30+ events firing. Is it possible to ensure that my function is only called once regardless of DOMSubtreeModified
is fired?
When using DOMSubtreeModified
I get multiple, sometimes 30+ events firing. Is it possible to ensure that my function is only called once regardless of DOMSubtreeModified
is fired?
2 Answers
Reset to default 6The Mutation Events
are performance hogs which can't really be tamed well. Therefore, they have been deprecated over a year ago and should be used only when really needed.
You could use the new and shiny Mutation Observers
from DOM Level 4 (follow the links there!). Where DOMSubtreeModified
fired a thousand times, MutationObserver
fires only once with all the modifications contained and accessible.
Works for (as of 2012/06):
- Chrome 18+ (prefixed,
window.WebKitMutationObserver
) - Firefox 14+ (unprefixed)
- WebKit nightlies
Other than that ... some hackish solution with removing the listener and scheduling to add it again in some time in future (a second or two) might be worth exploring.
You could delete the eventListener after the function was called the first time.
本文标签: javascriptDOMSubtreeModifiedHow to ensure it only fires onceStack Overflow
版权声明:本文标题:javascript - DOMSubtreeModified ... How to ensure it only fires once? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744214051a2595552.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论