简体   繁体   English

插入前置文字jQuery

[英]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? 我有一个jquery ajax聊天框,它在顶部添加了新消息,我如何将它们与该jquery动画一起滑动?

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. 因此,现在每条新消息都被包裹在具有当前时间ID的span标记中,因此它是唯一的。 We have also set it to hidden. 我们也将其设置为隐藏。

So now we slide the new one down. 所以现在我们将新的滑下来。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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