views:

35

answers:

1

I need a jQuery list like in Twitter's home page. This means, to have many posts listed, and then, after X seconds, another post is inserted at the top of the list, with an effect, and pushing the rest of them down.

+1  A: 

Exactly how to do this depends on what you want to add. As a basic principle, however, you can follow this method:

HTML:

<div id="container">
 <div>First item</div>
 <div>Second item</div>
</div>

Javascript:

$(document).ready(function(){
    setInterval(function(){
        $('<div>New item</div>').hide().prependTo('#container').slideDown('slow');
    },4000);
});

This will add a new div to the top of the container every 4 seconds. When it is added, it will slide down gradually and will push the existing divs down accordingly.

If you can provide some information about where your data is coming from, I can suggest how you might implement it.

lonesomeday
Well, I'm working on Ruby On Rails. Basically, my info comes from a collection of posts. Please let me know which info you need on this so I can provide it to you.
Brian Roisentul
Is it AJAX? What is the structure of your list? What is the structure of your received data?
lonesomeday
Well, there are two possibilities: 1) to load all the posts into a collection, containing its title, description, author, etc. 2) to dynamically load posts using ajax. I'd need both solutions for different kind of lists the site has.
Brian Roisentul
For (1), you would base this solely on intervals? I.e. every `n` seconds, add another div to the list until the whole collection has been added?
lonesomeday
I'll try. Thanks.
Brian Roisentul