jquery實現滾動到頁面底部時無限加載內容的代碼


  1. var p="{$other.p}";  
  2. if(p=="") p=1;  
  3.  var stop=true;//觸發開關,防止多次調用事件  
  4.  $(window).scroll(function() {    
  5.       //當內容滾動到底部時加載新的內容 100當距離最底部100個像素時開始加載.  
  6.       if ($(this).scrollTop() + $(window).height() + 100 >= $(document).height() && $(this).scrollTop() > 100) {    
  7.             
  8.           if(stop==true){  
  9.               stop=false;  
  10.               p=p+1;//當前要加載的頁碼    
  11.               canshu="?t={$other.t}&p="+p+"&cid={$other.cid}";  
  12.                //加載提示信息  
  13.                $("#showlists").append("<li class='ajaxtips'><div style='font-size:2em'>Loding.....</div></li>");  
  14.                $.get("__URL__/nextpage"+canshu,function(data){  
  15.                    $(".ajaxtips").hide();  
  16.                    $("#showlists").append(data);//把新的內容加載到內容的后面  
  17.                    stop=true;  
  18.                })  
  19.          }  
  20.       }    
  21.   });   
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM