代码之家  ›  专栏  ›  技术社区  ›  Prabhu

使用jQuery突出显示新添加的项

  •  0
  • Prabhu  · 技术社区  · 15 年前

    当用户将新注释(divCommentHtml)添加到注释列表(divComments)中时,我想将其高亮显示几秒钟并淡出。如何使用jquery做到这一点?这似乎不起作用:

     $('#divComments').prepend($divCommentHtml).effect("highlight", {}, 2000);  
    

    谢谢!

    4 回复  |  直到 15 年前
        1
  •  4
  •   Phil    15 年前

    使用 prepend ,您正在运行 #divComments 元素。

    试试这个(假设 $divCommentHtml 是jQuery对象)

    $divCommentHtml.prependTo('#divComments').effect('highlight', {}, 2000);
    

    或者也许

    $('#divComments').prepend($divCommentHtml)
                     .find(':first').effect('highlight', {}, 2000);
    
        2
  •  0
  •   alex    15 年前

    jQuery没有 effect() 开箱即用。 更新 哦,这是一个jQuery用户界面。继续:)

    $divCommentHtml.prepentTo('#divComments').effect("highlight", {}, 2000);
    

    我改变了它的工作方式所以你的方法是在 $divCommentHtml 反对。

        3
  •  0
  •   dpmguise    15 年前

    另一种方法是给$divCommentHtml一个ID,然后在它被预先设置好之后运行它

    $divCommentHtml = '<div id="myID">Some Contents</div>'
    $('#divComments').prepend($divCommentHtml);    
    $( "#myID" ).effect( 'highlight', {}, 2000);
    
        4
  •  -1
  •   Chinmayee G    15 年前

    你缺少括号 divCommentHtml . 支票 Live demo

    $('#divComments').prepend($(divCommentHtml)).effect("highlight", {}, 2000);