gitakachan / vue-project-collections-and-issues

vue issues
0 stars 0 forks source link

滑到最底下時隱藏bottom navbar #24

Open gitakachan opened 3 years ago

gitakachan commented 3 years ago

example form crowdfunding project(ProductDetails.vue )

(support、bottomNav 為子組件,當畫面滾動至support時隱藏bottomNav)

  methods: {
    hideBottomNav() {
      if (window.scrollY > this.$refs.support.offsetTop - 100) { // -100 使函數可以早點執行,不用真的等到滾動距離超過support距上距離 
        // console.log(window.scrollY, this.$refs.support.offsetTop); //頁面垂直位移量, support距最上方距離
        this.isHide = true; //bottomNav 設定隱藏的class綁定與否
      } else {
        this.isHide = false;
      }
    },
  },
  created() {
    window.addEventListener("scroll", this.hideBottomNav);
  },

  destroyed() {
    window.removeEventListener("scroll", this.hideBottomNav);
  },