vue 监听滚动事件

 window.addEventListener('scroll', this.handleScroll);
 document.removeEventListener('scroll', this.handleScroll);
handleScroll() {
      console.log('11');
      //获取滚动时的高度
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      //let oneHeight = this.$refs.scrollOne.scrollTop;
      //let twoHeight = this.$refs.scrollTwo.offsetHeight + oneHeight;
      //let threeHeight = this.$refs.scrollThree.offsetHeight + twoHeight;

      if (scrollTop > 0) {
        //滚动大于0的时候要做的操作
        // document.activeElement.blur();
        //window.pageYOffset = 0;
        //document.documentElement.scrollTop = 0;
        //document.body.scrollTop = 0;
      }
    },
posted @ 2021-07-30 10:17  握梅又闻花  阅读(310)  评论(0)    收藏  举报