鍍金池/ 問(wèn)答/HTML/ vue滾動(dòng)到底了,怎么判斷鼠標(biāo)繼續(xù)下滑時(shí)翻頁(yè)?

vue滾動(dòng)到底了,怎么判斷鼠標(biāo)繼續(xù)下滑時(shí)翻頁(yè)?

   mounted(){
          document.body.scrollTop = 0;
          this.a=document.body.scrollHeight||document.documentElement.scrollHeight;
          this.c =  document.documentElement.clientHeight;
          window.addEventListener('scroll',this.menu);


      },
        menu() {
              this.a = document.body.scrollHeight || document.documentElement.scrollHeight;

              this.b = document.body.scrollTop || document.documentElement.scrollTop;
              //通過(guò)判斷滾動(dòng)條的top位置與可視網(wǎng)頁(yè)之和與整個(gè)網(wǎng)頁(yè)的高度是否相等來(lái)決定是否加載內(nèi)容;
              if (this.b + this.c == this.a) {
                 // this.$router.push('./intelligenceb');
                  setTimeout(()=> {
                      console.log(滾動(dòng)到底了)
                     
                  },800);
                //  return;
              }

          }
回答
編輯回答
汐顏

沒(méi)看懂你的代碼。
我一般會(huì)用css將最外層的滾動(dòng)條挪到<app />上,處理的話就常規(guī)處理吧。
mounted階段綁定事件,destoryed時(shí)候解除綁定。
事件綁定到app上(或者你當(dāng)前判斷條件所在的dom上),用你描述的判斷條件就好。
其實(shí)有很多現(xiàn)成的上拉加載的組件,你可以直接用。
比如這個(gè)
這是它的源代碼
判斷條件:
scrollEventTarget.scrollHeight - viewportBottom <= distance;
跟你講的差不多

2017年7月21日 22:14