jquery.infinitescroll无限加载插件

一、引入所需js插件

<script type="text/javascript" src="js/jquery-1.10.0.min.js"></script>
<script type="text/javascript" src="js/jquery.infinitescroll.min.js"></script>

二、html

1、创建一个容器

<div id="conversation">
    <div class="comment">...</div>
    <div class="comment">...</div>
    ...
</div>

2、添加翻页的链接

<div id="page-nav">
    <a href="conversations.php?page=2"></a>
</div>

三、所需的css

在加载的时候,页面会出现一个loading的层(id是#infscr-loading),这个部分的样式需要我们自己去定义,下面是我自己网站的一个半透明黑色的样式,如果你喜欢,可以直接拿去用

#infscr-loading { 
  text-align: center;
  z-index: 100;
  position: fixed;
  left: 45%;
  bottom: 40px;
  width: 200px;
  padding: 10px;
  background: #000; 
  opacity: 0.8;
  color: #FFF;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
}

四、js自动加载部分

    infiniteScroll = function() {
        // infinite scrolling
        var $container = $('#conversation');

        $container.infinitescroll({
            binder: $('#conScroll'),       // used to cache the selector
            navSelector  : '#page-nav',    // selector for the paged navigation
            nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
            itemSelector : '.comment',     // selector for all items you'll retrieve
            pixelsFromNavToBottom: 150,
            extraScrollPx: 50,
            debug        : true,
            prefill      : true,
            bufferPx     : 1,              //提示语展现的时长,数字越大,展现时间越短
            path : function(page){
                return 'conversation.html';
            },
            loading: {
                finishedMsg: 'no more comments!',
                msgText: 'onload old comments',
                img: 'img/loading-dark.gif'
            }
        },       
        function( nextComments ) {
            var $nextComm = $( nextComments );
            $container.append($nextComm);
        });
    }
    infiniteScroll();
    //onload more
    /*$('#conScroll .onloadmore').click(function(){
        $("#conversation").infinitescroll('retrieve');; //比如加到某个click事件中
    });*/

五、加载“更多”

// 取消scroll绑定
$('#conScroll').unbind('.infscr');

// 手动点击的元素
$('#next').click(function(){
    $('##conversation').infinitescroll('retrieve');
});

demo下载地址 http://download.csdn.net/detail/jiangjundriver/9871458

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值