美文网首页
ResizeObserver使用

ResizeObserver使用

作者: 喜欢走弯路的人 | 来源:发表于2024-01-23 15:35 被阅读0次

HTML:

<div class="main" ref="main" style="width:200px;height:200px;background:green;">

      <chatView></chatView>

</div>

CSS:

.main {

    resize: both;

    overflow: auto;

}

JS:

    mounted(){

      // (1) 定义被观察的目标对象

      let main=this.$refs.main

      // (2)定义一个观察者 观察 目标对象的变化

      const resizeObserver = new ResizeObserver((entries)=>{

        for(let entry of entries){

          console.log(entry.contentRect,'===entrys====')

        }

      })

      // (3)观察者观察目标对象

      resizeObserver.observe(main);

    },

相关文章

网友评论

      本文标题:ResizeObserver使用

      本文链接:https://www.haomeiwen.com/subject/hdbuodtx.html