以body为例

<script>
    var initHeight = document.body.clientHeight;
    // Firefox和Chrome早期版本中带有前缀
    var MutationObserver = window.MutationObserver|| window.WebKitMutationObserver || window.MozMutationObserver
    // 选择目标节点
    var target = document.body;
    // 创建观察者对象
    var observer = new MutationObserver(function(mutations) {
      if(initHeight != document.body.clientHeight) {
        initHeight = document.body.clientHeight;
        console.log('222',initHeight);
      }
    });
    // 配置观察选项:
    var config = {
      attributes: true
    }
    // 传入目标节点和观察选项
    observer.observe(target, config);
    // 随后,你还可以停止观察
    //observer.disconnect();
</script>

 

 posted on 2021-04-30 14:17  一个大柚子~  阅读(2304)  评论(0编辑  收藏  举报