JS 네이티브 JS 판단 스크롤 막대 끝까지 미끄럼(애플 사파리 호환)

1569 단어
  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);
}
 

  
다음으로 전송:https://www.cnblogs.com/winyh/p/7576134.html

좋은 웹페이지 즐겨찾기