Js window.scroll multiple request problem

the requirement is to load more. Tab switches to that module and calls the corresponding interface. The code is as follows:

loadMore.js plugin

;(function(w,$){
   
  var loadmore = { 
    /* 
     * 
     * @param callback 
     * @param config 
     * */
    get : function(callback, config){
      var config = config ? config : {}; /**/
 
      var counter = 1; /**/
      var pageStart = 1;
      var pageSize = config.size ? config.size : 10;
 
      /**/
      $(document).on("click", ".js-load-more", function(){
        counter PP;
        pageStart = counter;
         
        callback && callback(config, pageStart, pageSize);
      });
       
      /*,*/
      config.isEnd = false; /**/
      config.isAjax = false; /**/
     
     function sleep(delay) {
      var start = (new Date()).getTime();
      while ((new Date()).getTime() - start < delay) {
        continue;
      }
    }
     
     console.log(config.isAjax);
     $(window).scroll(function(){
        /**/
        if(!config.scroll){
          return;
        }
        /**/
        if(config.isEnd == true || config.isAjax == true){
          return;
        }

        /*100 */
       if ($(document).height() - $(this).scrollTop() - $(this).height()<100){
             console.log(1);
             config.isAjax = true;
          sleep(600);
          counterPP;
          pageStart = counter;
          callback && callback(config, pageStart, pageSize);    
        }
      });
 
      /**/
      callback && callback(config, pageStart, pageSize);
    },
       
  }
 
  $.loadmore = loadmore;
})(window, window.jQuery || window.Zepto);

Business Code:

$(".nav_bar div").click(function(){
        $(".spinner").css("display","block");
        $(".loadTip").css("display","none");
        $(".loadTip").html(" ");
        $(this).addClass("active").siblings().removeClass("active");
        var currentBox=$(this).attr("data-name");
        var type=$(this).attr("data-type");
        $("."+currentBox).show().siblings().hide();
            //    
        var userId = $.getUrlParam("userId");
           if(type==0){
              $("-sharpallBox").html("");
              $("-sharpsrBox").html("");
              $("-sharpqyBox").html("");
              
              $.loadmore.get(getAllData, {
                scroll: true, //false,
               size:10, //10
               flag: 1, //
               isAjax:false,
               isEnd:false
              });         
            } else if(type==1){
              $("-sharpallBox").html("");
              $("-sharpsrBox").html("");
              $("-sharpqyBox").html("");
               $.loadmore.get(getIncomeData, {
                 scroll: true, //false,
                 size:10, //10
                 flag: 1, //
                 isAjax:false,
                 isEnd:false
              });        
            } else if(type==2){
               $("-sharpallBox").html("");
               $("-sharpsrBox").html("");
               $("-sharpqyBox").html("");
               $.loadmore.get(getExchangeData, {
                  scroll: true, //false,
                  size:10, //10
                  flag: 1, //
                  isAjax:false,
                  isEnd:false
              });        
            }
    });```
    
    
   tab
  

function getAllData (config,pageNum,size) {

    //    
    var userId = $.getUrlParam("userId");
    var size = config.size;
    config.isAjax = true;
    $.ajax({
        type:"post",
        url:"http://www.tojoycloud.org/appfront/m/app/prize/tjBeansDetail",
        data:"{"userId":""+userId+"","type":"0","page":""+pageNum+"","size":""+size+""}",
        dataType:"json",
        contentType:"application/json;charset=utf-8",
        success:function(data){
            if(data.responseCode==1){
                isClick = true;
                config.isAjax = false;
                var len=data.dataObj.length;
                if(pageNum == 1){
                  if(data.dataObj.length<size){
                      config.isEnd = true;
                     $(".spinner_allBox").css("display","none");
                     $(".loadTip_allBox").css("display","none");
                  }
                } else{
                  if(data.dataObj.length<size){
                      config.isEnd = true;
                      $(".spinner_allBox").css("display","none");
                      $(".loadTip_allBox").css("display","block");
                      $(".loadTip_allBox").html(" ");
                  }    
                }
                
                var str="";
                var srStr="";
                var len=data.dataObj.length;
                /*$("-sharpallBox").html("");*/
                var srcOrigin = "";
                for(var i=0;i<len;iPP){
                    if(data.dataObj[i].tjBeansControl==1){
                        console.log(data.dataObj[i].userId)
                        if(data.dataObj[i].userPic){
                          srcOrigin = (ossUrl+data.dataObj[i].userPic)    
                        } else {
                            srcOrigin = "img/user.png"
                        }
                        str+="<li><p class="srTitle">

<div class="srDetaile">"; str+="<img onclick="goIndexFun(this)" data-userid="+data.dataObj[i].userId+" class="userImg" src=""+srcOrigin+""/>"; str+="<div class="srNamezw"><span class="srName">"+data.dataObj[i].userName+"</span>"; str+="<span class="srZw">"+data.dataObj[i].userPosition+"</span>"; str+="<p class="srgs">"+data.dataObj[i].company+"

</div>"; str+="<p class="srTime">"+data.dataObj[i].createTime+"

</div>"; str+="<div class="srNum">+"+data.dataObj[i].tjBeansNum+"</div>"; str+="</li>" } else if(data.dataObj[i].tjBeansControl==0 ||data.dataObj[i].tjBeansControl==2){ if(data.dataObj[i].type=="0"){ var dhType=""; }else if(data.dataObj[i].type=="1"){ var dhType=""; }else if(data.dataObj[i].type=="2"){ var dhType=""; }else if(data.dataObj[i].type=="3"){ var dhType=""; } str+="<li><div class="qyLeft">"; str+="

"+dhType+"

"; str+="<p class="qyTime">"+data.dataObj[i].createTime+"

</div>"; str+="<div class="qyRight">-"+data.dataObj[i].tjBeansNum+"</div></li>" } } } $("-sharpallBox").append(srStr+str); } } }); }


  bug  tab
    


Dec.07,2021

did not do anti-shaking. Scroll is a high frequency event.

refer to here

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38840-2c112.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38840-2c112.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?