开发者

jQuery highlight effect before remove()

Consider the following snippet:

$('.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();
...

I'd like to highlight the actual row before trashing (.remove()开发者_运维问答) it. If i don't .remove() the item, highlight working.

How can i highlight first, then remove element?


You can use the callback functionality of effect and fadeOut to do actions when the first action has finished:

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

This says "highlight _item. When this is finished, fade it out. When this is finished, remove it."


Yo ushould be able to assign a callback on the fadeOut:

$('.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(); });
    }
});

hope this helps.


You need to queue the .remove()

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜