MutationObserver是否观察到跨度的offsetHeight属性更改?

问题描述 投票:0回答:1

我正在尝试使用MutationObserver来观察跨度何时更改高度(当跨度内部的文本更改大小时)。但是,即使检查span的offsetHeight属性确实显示了更改,似乎也没有引起任何突变。没有观察到财产变化吗?

let mutationobserverconfig = {
  attributes: true,
  childList: true,
  subtree: true
}; 

function onmutation(mutations) {

  for (let mutation of mutations) {
    log("resizemutationobserver");
    // for
  }

  // onmutation
}

let resizemutationobserver;

function addresizemutationobserver(element, callback) {

// callback is in the module using this function


  resizemutationobserver = new MutationObserver(onmutation);
  let targetnode = $(element)[0];
  resizemutationobserver.observe(targetnode, mutationobserverconfig); //

}
javascript mutation-observers
1个回答
0
投票

在这个问题上,区分attaributeproperty很重要。在this answer中有详细解释。

HTML元素具有属性,其中一些由相应的DOM接口(节点)的属性反映。

该界面还有一些其他的[[properties(例如offsetHeight),它们没有匹配的HTML属性。

MutationObserver观察到对属性所做的更改时,将不会监视offsetHeight的更改。
© www.soinside.com 2019 - 2024. All rights reserved.