下拉加载

1、Vue方法
mouseWheel(e) {
      let eve = window.event || e;
      let divscroll = document.getElementById("wrap");
      divscroll.onmousewheel = e => {
        let scrollTop = divscroll.scrollTop; //页面上卷的高度
        let wholeHeight = divscroll.scrollHeight; //页面底部到顶部的距离
        let divHeight = divscroll.clientHeight; //页面可视区域的高度

        if (scrollTop + divHeight >= wholeHeight) {
          if (!this.isLoad) {
            if (this.pageNum < this.logNum) {
              this.isLoad = true;
              this.loading = true;
              this.pageNum++;
              this.getSystemLog(1);
            }
          }
        }
        if (scrollTop == 0) {
          if (eve.wheelDelta > 0) {
            if (!this.isLoad) {
              this.isLoad = true;
              this.pageNum = 1;
              this.getSystemLog(0);
            }
          }
        }
      };
    },
2、原生方法
var divscroll=document.getElementById('testDiv');
    function divScroll(){
        var scrollTop=divscroll.scrollTop;//页面上卷的高度
        var wholeHeight=divscroll.scrollHeight;//页面底部到顶部的距离
        var divHeight=divscroll.clientHeight;//页面可视区域的高度
        if(scrollTop+divHeight>=wholeHeight){
            alert('我到底部了');
        }
        if(scrollTop==0){
            alert('我到顶部了');
        }
    }
    divscroll.οnscrοll=divScroll;

你可能感兴趣的:(下拉加载)