Jquery无限滚动双打印

时间:2013-03-07 05:20:39

标签: javascript infinite-scroll

所以我一遍又一遍地研究,试图消除这个问题无济于事。我是Javascript的亲戚Noob。我遇到的问题是,当事件处理程序触发时,它会打印出我想要的新的20个项目,但之前的20个项目会在一次加载后冻结。 任何帮助是极大的赞赏 这是代码:

JAVASCRIPT FUNCTION:

<script type="text/javascript">
    $(window).scroll(function(){
        if($(window).scrollTop() == $(document).height() - $(window).height()){
            $('div#loadMoreComments').show();
            $.ajax({
                url: "loadeR.php?lastComment=" + $(".postedComment:last").attr("id"),
                success: function(html){
                            if(html){
                                $("div#postedComments").append(html);
                                $("div#loadMoreComments").hide();
                            }else{
                                $("div#loadMoreComments").replaceWith("Showing All Comments!");
                            }
                        }
            });
        }
    });
</script>

APPEND PAGE PHP:

if($_GET['lastComment']){
    $NewAll = mysql_query('select*from scroll WHERE id < "'.$_GET['lastComment'].'" ORDER BY id DESC LIMIT 0,20');
    $a = mysql_num_rows($NewAll);
    for($i=0;$i<$a;$i++){
        $id = mysql_result($NewAll,$i,'id');
        $name = mysql_result($NewAll,$i,'name');
        $text = mysql_result($NewAll,$i,'text');
        echo "
            <div class='postedComment' id='$id postedComment'>
            <img src='prime1.jpg' id='userimage'/>
                <div id='rightcontainer'>
                    <div id='walluser'>User Name $id</div>
                    <div id='wallcontent'>Comment/Content $name</div>
                    <div id='walltime'>Time posted $text</div>
                </div>
            </div>
        ";  

    }
}

INITIAL DIV已加载

<div id="postedComments">
    <?php
        $All = mysql_query('select*from scroll ORDER BY id DESC LIMIT 0,20');
        //SELECT * FROM [insert table name] ORDER BY [insert unique counter] DESC LIMIT 0,[MAX #]
        $a = mysql_num_rows($All);
        for($i=0;$i<$a;$i++){
            $id = mysql_result($All,$i,'id');
            $name = mysql_result($All,$i,'name');
            $text = mysql_result($All,$i,'text');
            echo "
                    <div class='postedComment' id='$id postedComment'>
                        <img src='prime1.jpg' id='userimage'/>
                        <div id='rightcontainer'>
                            <div id='walluser'>User Name $id</div>
                            <div id='wallcontent'>Comment/Content $name</div>
                            <div id='walltime'>Time posted $text</div>
                        </div>
                    </div>
                "; 
        }

    ?>
</div>
<div id='loadMoreComments' style="display:none;"><img src="js/loadwheel.gif"/></div>

0 个答案:

没有答案