2010-11-09 60 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(); }); 
    } 
}); 

希望這會有所幫助。