重新加载新的内容,同时滚动加载、内容

2023-09-10 15:51:09 作者:哥在夜、喝酒

即时通讯使用下面的jQuery的,这台最后一个项目的ID在UL为last_item。

Im using the following jQuery, which sets the id of the last item in a UL to 'last_item'.

function oldest() {
 j('ul li:last-child').addClass( 'last_item' );
 oldestName = j('.last_item').attr('id');
 alert('last ID is:'+ oldestName +'.');
}

j(window).scroll(function(){
    if  (j(window).scrollTop() == j(document).height() - j(window).height()){
            j.ajax({
                url: "older.php?oldest="+oldestName+"",
                cache: false,
                success: function(html){
                    j(".older").html(html);
                    oldest();
                }
            })
    }
}); 

oldest(); //Call function on page load

$('.button2').click(function() {
    j('.older ul > *').clone().hide().appendTo('.tweets ul').slideDown();
    oldest();
});

虽然滚动older.php被称为包含:

While scrolling older.php is called which contains:

$oldest = $_GET['oldest'];

$getolder = mysql_query(" SELECT * FROM table where date < $oldest ORDER BY date DESC LIMIT 20");

不过目前什么情况是从数据库中的记录确实会拉了回来,存放在一个隐藏的DIV。然后我用了jQuery将这些记录添加到列表的末尾。

However what currently happens is the records from the database do get pulled back, stored in a hidden DIV. I then use the jQuery to add these records to the end of the list.

但下一次我滚动到页面和preSS按钮的下方,同样的记录添加到列表中。

However the next time i scroll to the bottom of the page and press the button, the same records are added to the lists.

任何可以帮我找出这是为什么?

Can any help me to find out why this is?

本质上,它似乎$最古老的心不是被更新为新的最后UL项目的日期。

Essentially it seems $oldest isnt being updated with the new last UL item date.

推荐答案

您需要删除列表项原来的last_item类,你将它添加到新的最后一个项目之前...

You'll need to remove the original "last_item" class from list item before you add it to the new last item...

 j('ul li').removeClass( 'last_item' );