3

由于观察到的属性被更改,在更新 DOM 后是否会触发事件?

具体来说,我需要更改容器的 scrollTop 属性以在添加新内容时显示新内容。我现在必须使用超时来等待 DOM 更新,然后再将 scrollTop 设置为新的 scrollHeight。

4

1 回答 1

3

谢谢你的问题。据我了解,更改通过模型和 DOM 异步传播。目前尚不清楚是否有一个“好的,从字面上看,所有的事情都完成了更新”事件(我可能是错的)。

但是,我使用 Mutation Observers 来了解我的 DOM 中的某些内容何时发生变化。如果您能够在 DOM 中查看特定位置的更改(或更改),请尝试 Mutation Observers:https ://github.com/sethladd/dart-polymer-dart-examples/tree/master/web/mutation_observers

这是一个例子:

  MutationObserver observer = new MutationObserver(_onMutation);
    observer.observe(getShadowRoot('my-element').query('#timestamps'), childList: true, subtree: true);


  // Bindings, like repeat, happen asynchronously. To be notified
  // when the shadow root's tree is modified, use a MutationObserver.

  _onMutation(List<MutationRecord> mutations, MutationObserver observer) {
    print('${mutations.length} mutations occurred, the first to ${mutations[0].target}');
  }
于 2013-10-08T16:55:39.820 回答