html监听标签的resize

<html>
<body>
<div id="div1" style="width:100%;height:100%;">
    <div id="div2" style="width:80%;height:80%;border:5px solid #000;">
        <div style="width:60%;height:60%;border:3px solid #808080;"></div>
    </div>
</div>
</body>
<script>
    var robserver = new ResizeObserver(entries => {
        console.log(entries.length);
        for (const entry of entries) {
            console.log("resize:" + entry.target.id);
          }
    });
    robserver.observe(document.body.querySelector("#div1"));
    robserver.observe(document.body.querySelector("#div2"));

    //取消监听
    //robserver.unobserve(document.body.querySelector("#div1"));
    //robserver.unobserve(document.body.querySelector("#div2"));
</script>
</html>

 

posted @ 2020-12-03 17:21  IWing  阅读(485)  评论(0编辑  收藏  举报