首页 > 其他分享 >vue 监听滚动事件到某个位置删除或者添加元素

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

时间:2022-12-06 15:46:58浏览次数:44  
标签:vue 滚动 handleScroll window var scrollTop document 监听

首先添加监听事件

 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)
    }

 

标签:vue,滚动,handleScroll,window,var,scrollTop,document,监听
From: https://www.cnblogs.com/sgdkg/p/16955452.html

相关文章