js滚动条滚动到底部触发事件

//获取节点
      const scrollDiv = this.$refs.mypklogList  //vue的写法 mypklogList是表现中 ref=“mypklogList”
      const scrollDiv=document.getElementById(‘id’) //js的写法 上面的和这个选择一个
      const offsetHeight = scrollDiv.offsetHeight;
      //绑定事件
      scrollDiv.addEventListener('scroll', function() {
        const scrollTop = scrollDiv.scrollTop;
        const scrollHeight = scrollDiv.scrollHeight;
        if (offsetHeight + scrollTop >= scrollHeight ) {
         	//触发事件
        }
      })```

猜你喜欢

转载自blog.csdn.net/j244233138/article/details/96727595