赞
踩
在主体盒子的高度<=页面向下滚动的距离加屏幕高度的情况进行判断是否执行(在满足条件时新增数据)
根据 this.ok(默认为true) 判断是否为1秒内第一次执行,如果为true执行下列代码
将 this.ok 设为 fales,下次再触发scroll事件时判断不通过以此阻止代码多次执行
执行新增数据代码
设置一个炸弹定时器,在1秒内再次触发 scorll 事件时,this.ok 的值为 false ,新增方法不会被执行,在1秒后执行其中将 this.ok 设为 true的代码,这时再 触发 scorll 事件时 this.ok 的值为 true ,新增方法才会被执行。
export default { data() { return { boxheight: 0, topheight: 1, ok: true, }; }, methods: { throttle() { this.boxheight = Number(this.$refs.element.offsetHeight); // 获取主体盒子高度 this.topheight = Number(document.documentElement.scrollTop) + Number(document.documentElement.clientHeight); // 获取页面向下滚动的距离加屏幕高度 if (this.topheight >= this.boxheight) { // 在主体
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。