JS 原生JS 判断滚动条滑动到底部(兼容苹果safari)

  ListenerScoller () {
    var pageIndex = 1;
    var startX, startY; 
    document.addEventListener('touchstart',function (ev) { 
      startX = ev.touches[0].pageX; 
      startY = ev.touches[0].pageY; 
    }, false); 


    let _this = this;
    document.addEventListener('touchend',function (ev) {
      var endX, endY; 
      endX = ev.changedTouches[0].pageX; 
      endY = ev.changedTouches[0].pageY; 
      var dy = startY - endY;
      var reach = Boolean;
      var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;

      console.log(scrollTop); 
      document.documentElement.scrollHeight == document.documentElement.clientHeight || document.body.clientHeight(兼容苹果safari) + scrollTop ? reach = true : reach = false
      console.log(reach)

      if(dy>30 && reach){
        pageIndex++;
        _this.setState({
          isLoad:true
        })

      _ENV.post(_ENV.HOST+'/distributor/ticket-record?page='+pageIndex).then(data => {
        let newData = data.data.list;
        let original = _this.state.buys;
        if(data.data.isLastPage){
          _this.setState({
            loadText:'没有更多数据'
          })
        }
        let arr = original.concat(newData);
        console.log(arr);
        _this.setState({
          buys:arr
        });
      }).catch(error=>{
        console.log(error);
      });
    }

    }, false);
}
 

  

posted @ 2017-09-22 17:45  winyh  阅读(1516)  评论(0编辑  收藏  举报