JS 滚动到底部触发事件

2020-09-18  本文已影响0人  _feest

created的时候添加上事件

window.addEventListener('scroll',this.bodyScroll)


bodyScroll () {

let scrollTop =document.documentElement.scrollTop ||document.body.scrollTop

        let clientHeight =document.documentElement.clientHeight ||document.body.clientHeight

        let scrollHeight =document.documentElement.scrollHeight ||document.body.scrollHeight

        if ((clientHeight >0 &&scrollTop >0) && (scrollTop +clientHeight ===scrollHeight)) {

             if (!this.finished) {this.getListData(true) }

        }

}

离开组件的时候要销毁 滚动事件

destroyed () { // 销毁滚动加载 window.removeEventListener('scroll', this.bodyScroll)}

上一篇 下一篇

猜你喜欢

热点阅读