记录监听元素重叠度

6 篇文章 0 订阅
4 篇文章 0 订阅

页面代码

 <div id="parent" style="height: 500px;overflow:scroll;border: 1px solid #000">
       <div v-for="item in numbers" :key="item">{{item}}</div>
      <div id="loading">
        <i class="el-icon-loading"></i>
      </div>
    </div>

JS

export default {
  name: 'page1',
  data () {
    return {
      numbers: Array.from({ length: 100 }, (_, i) => i + 1)
    }
  },
  methods: {
    // 新增数据
    addCol () {
      const a = Array.from({ length: 100 }, (_, i) => i + 101)
      this.numbers = this.numbers.concat(a)
    },
    init () {
      const that = this
      const loadingDom = document.getElementById('loading')
      const parentDom = document.getElementById('parent')
      const ob = new IntersectionObserver(function (entries) {
        const ent = entries[0]
        if (!ent.isIntersecting) {

        } else {
          console.log('加载更多', ent)
          that.addCol()
        }
      }, {
        root: parentDom,
        threshold: 0.5
      })
      ob.observe(loadingDom)
    }

  },
  mounted () {
    this.init()
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值