vue监听元素滚动到底部

本文转载自: https://www.jb51.net/article/147462.htm

 

created() {
    this.$nextTick(() => {
      const el = document.querySelector('.activityText');
      const offsetHeight = el.offsetHeight;
      el.onscroll = () => {
        const scrollTop = el.scrollTop;
        const scrollHeight = el.scrollHeight;
        if ((offsetHeight + scrollTop) - scrollHeight >= -1) {
          // 需要执行的代码
          console.log('已滚动到底部')
        }
      };
    });
  },

如果监听元素滚动失效,css改成下面写法。

.wrListBox {
        width: 100%;
        height: 100%;
        overflow-y: scroll;
}

 

posted @ 2020-06-03 15:30  本溢  阅读(4483)  评论(0)    收藏  举报