开发者

auto updating a list of items with jQuery

I'd like to create a list of the latest content on my we开发者_运维百科bsite and I'd like it to update every 3 seconds. New items have to be added to the top of the list with an animation. I't should look like the list of tweets on twitter's index page (the index page for not logged in users).

I'm familar with jQuery, and I'm wondering if somebody know a plugin that I can use. I also use PHP to send the info from the server, so this wil not be a problem, I just need the jQuery code to handle this.

Do you, guys know a nice jQuery plugin that can do this for me ? Thanks!


You don't need to have a plugin for this as it's fairly simple to do in jQuery itself.

Some bits you do need to know about are the jQuery prepend and fadeIn methods - that's about it.

The following code will fade a new item to the top of the list every 3 seconds. A demo of it working can be found here: http://jsfiddle.net/jonathon/7xvY5/

var itemCount = 1;

function addItem() {
    newItem = $("<li>Item " + itemCount + "</li>").hide();
    $("#mylist").prepend(newItem);
    newItem.fadeIn();

    itemCount++;
    setTimeout(addItem, 3000);
}

setTimeout(addItem, 3000);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜