vue 监听滚动事件到某个位置删除或者添加元素

首先添加监听事件

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

事件处理

handleScroll() {
            var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
            var visheight = document.body.offsetHeight
            var allheight = this.$refs.pdfWrap.clientHeight
            if (allheight - visheight - scrollTop <= 800) {
                this.showGif = false
            }
        }

页面销毁后处理

 beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll)
    }

 

posted @ 2022-12-06 15:30  xiaoxiaoxigua  阅读(137)  评论(0编辑  收藏  举报