Implementing MutationObserver in place of DOMSubtreeModified

心不动则不痛 提交于 2019-12-05 13:21:14
  • Put the code in place of the old DOM event and use your sel variable as the observation target;
  • Use childList option in MutationObserver because subtree doesn't specify what to look for;
  • There's no need to check the mutations since you subscribe only to one type.

$('.custom-multiselect').each(function() {
    var sel = this;
    adjustHeight(sel);

    new MutationObserver(function() {
        adjustHeight(sel);
    }).observe(sel, {childList: true, subtree: true});
});

Or, if you like .bind for some reason:

new MutationObserver(adjustHeight.bind(null, sel))
    .observe(sel, {childList: true, subtree: true});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!