滚到底部自动加载 像新浪微博那样,

本文介绍了一个使用jQuery实现的无限滚动加载功能,通过监测用户滚动位置并自动加载更多内容,适用于大量数据展示的网页应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script>
    if(true){
        jQuery(function(){
           var m = window.location.search.match(/p=(\d+)/);
           var curPage = m ? parseInt(m[1]) : 1;
           var loading = false;

           jQuery("#content").scroll(function(){
               if ( curPage >= 1 && !loading && this.scrollHeight -
                       this.scrollTop - this.offsetHeight < this.offsetHeight ) {
                   loading = true;
                   if ((25*curPage) < 79346) {
                        DWRUtil.setValue("scrollStats", 25*(curPage+1) + " of " + 79346);
                    } else {
                        DWRUtil.setValue("scrollStats", 79346);
                    }
                   $("progressIndicator").style.display="block";
                   jQuery.ajax({
                       type: "GET",
                       dataType: "html",
                       url: window.location + (window.location.search != '' ? "&" : "?") + "type=html&p=" + ( ++curPage ),
                       success: function( html ){
                           html = jQuery.trim( html );

                           if ( html ) {
                               jQuery("#content-inner").append( html );
                               
//                             }
                           } else
                               curPage = 0;
                       },
                       complete: function(){
                           loading = false;
//                         alert(window.location.pathname + (window.location.search != '' ? ""+ window.location.search +"&" : "?") + "p=" + ( curPage ))
                           pageTracker._trackPageview(window.location.pathname + (window.location.search != '' ? ""+ window.location.search +"&" : "?") + "p=" + ( curPage ));
                           _qacct="p-ebK_XdQH1HeLo"; quantserve();
                           $("progressIndicator").style.display="none";
                       }
                   });
               }
           });
        });
    }
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值