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

时间:2019-10-04 20:12:25

标签: javascript mutation-observers

我正在尝试使用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); //

}

1 个答案:

答案 0 :(得分:0)

在这个问题上,区分 attaribute 属性非常重要。 this answer中对此进行了详细说明。

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

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

MutationObserver观察到对属性所做的更改时,将不会监视offsetHeight的更改。

相关问题