export default {
  name: "nav-bar",
  data() {
    return {
      isFixed: false, //当滚动条高度大于152时是否定位
      scrollHeight: 152
    };
  },
  mounted() {
    window.addEventListener("scroll", this.initHeight);
  },
  methods: {
    // 实现吸顶效果,判断滚动条距离顶部的距离
    initHeight() {
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      this.isFixed = scrollTop > this.scrollHeight ? true : false;
    }
  },
  destroyed() {
    window.removeEventListener("scroll", this.initHeight, false);
  }
};

 

相关文章:

  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2022-02-06
  • 2022-12-23
  • 2021-07-23
  • 2021-06-04
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
相关资源
相似解决方案