[英]Highlighting a newly added item using jQuery
When a user adds a new comment (divCommentHtml) to a list of comments (divComments), I would like to highlight it for a few seconds and fade it away. 当用户将新评论(divCommentHtml)添加到评论列表(divComments)时,我想突出显示它几秒钟并使其消失。 How can you do this with jquery?
你怎么用jquery做到这一点? This doesn't seem to work:
这似乎不起作用:
$('#divComments').prepend($divCommentHtml).effect("highlight", {}, 2000);
Thanks! 谢谢!
Using prepend
, you're running the UI effect on the #divComments
element. 使用
prepend
,您可以在#divComments
元素上运行UI效果。
Try this (assuming $divCommentHtml
is a jQuery object) 试试这个(假设
$divCommentHtml
是一个jQuery对象)
$divCommentHtml.prependTo('#divComments').effect('highlight', {}, 2000);
Or perhaps 也许
$('#divComments').prepend($divCommentHtml)
.find(':first').effect('highlight', {}, 2000);
jQuery doesn't have an effect()
out of the box. jQuery没有开箱即用的
effect()
。 Update Oh it's a jQuery UI thing. 更新哦,这是一个jQuery UI。 Carry on :)
继续 :)
$divCommentHtml.prepentTo('#divComments').effect("highlight", {}, 2000);
I changed how it works so your method is being ran on the actual $divCommentHtml
object. 我更改了它的工作方式,以便在实际的
$divCommentHtml
对象上运行您的方法。
Another alternative is to give $divCommentHtml an ID then run the effect after it's prepended 另一种选择是给$ divCommentHtml一个ID,然后在预先添加效果后运行效果
$divCommentHtml = '<div id="myID">Some Contents</div>'
$('#divComments').prepend($divCommentHtml);
$( "#myID" ).effect( 'highlight', {}, 2000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.