vue实现通过监听滚动条位置,显示或隐藏

142 阅读1分钟
mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
methods: {
  
    handleScroll() {
      let top = document.documentElement.scrollTop;
      if (top > 150) {
        this.topShow = true;
      } else if (top < 150) {
        this.topShow = false;
      }
    },
},