jQuery “push down” list as in Twitter's home page

别等时光非礼了梦想. 提交于 2019-12-22 12:23:51

问题


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:


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.



来源:https://stackoverflow.com/questions/3926719/jquery-push-down-list-as-in-twitters-home-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!