简体   繁体   中英

Slide in prepended text jQuery

I have a jquery ajax chat box that adds new messages to the top, how would I have them slide in with that jquery animation?

My current code:

$('#chatbox').prepend(document.getElementById('new_posts').innerHTML);

I'm sure it's simple but I'm a newbie at it.

Well you could try adding the prepended text like so.

var d = new Date();
$('#chatbox').prepend('<span id="' + d.getTime() + '" style="display:none">' + document.getElementById('new_posts').innerHTML + '</span>');

So now each new message is wrapped in a span tag with an id of the current time, so it is unique. We have also set it to hidden.

So now we slide the new one down.

$('#chatbox span#' + d.getTime()).slideDown('slow');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM