2010-11-09 65 views
7

考虑下面的代码片段:搬迁之前的jQuery高亮效果()

$('.remove_item').click(function(e) { 
    var _item = $(this).closest('.cart_item'); 
    if(confirm('Biztosan törölhetem a terméket a kosárból?')) { 
     _item.effect('highlight', {}, 100).stop().fadeOut('fast'); 
     _item.remove(); 
... 

我想捣毁(.remove())前突出实际行吧。如果我不.remove()该项目,突出显示工作。

我该如何突出显示,然后删除元素?

+2

请参阅此处:http://stackoverflow.com/questions/510761/jquery-delete-dom-element-after-fading-out – mamoo 2010-11-09 13:16:08

回答

16

您可以使用effectfadeOut回调功能做动作时的第一个动作完成:

_item.effect('highlight', {}, 100, function(){ 
    $(this).fadeOut('fast', function(){ 
     $(this).remove(); 
    }); 
}); 

这是说“突出显示_item。完成后,将其淡出,完成后将其删除。“

+0

感谢您的详细解释。 – fabrik 2010-11-09 13:27:17

+0

你不需要回调'.effect()'。 '.fadeOut()'将在'.effect()'之后自动排队运行。 – user113716 2010-11-09 13:27:37

+0

@patrick感谢您的澄清 - 我有时会被jQuery队列弄糊涂... – lonesomeday 2010-11-09 17:26:08

0

您需要排队的一个.remove()

_item.queue(function() { $(this).remove(); }); 
5

呦ushould能够在淡出分配回调:

$('.remove_item').click(function(){ 
    if(confirm('Biztosan törölhetem a terméket a kosárból?')) 
    { 
     $(this).closest('.cart_item').fadeOut(500, function() { $(this).remove(); }); 
    } 
}); 

希望这会有所帮助。