试图使一些div fadeOut然后被删除

我正在尝试制作一些div fadeOut然后被删除。

$("article.articles .thumb a").click(function() { $(this).parent().parent().addClass("selected"); $("article.post").not(".selected").fadeOut(500).delay(1500).remove(); $('#stream').isotope('reLayout'); }); 

但是这些div很快就会消失而不会褪色。

我究竟做错了什么?

你可以使用fadeOut()回调函数,它在淡入淡出效果完成后执行。

.fadeOut([duration] [,callback])

 $("article.post").not(".selected").fadeOut(500, function(){ $(this).remove(); }) 

要么:

 $("article.post").not(".selected").fadeOut(500).delay(2000).queue(function(){ $(this).remove() }) 

在删除div之前,你不是在等待div淡出。 您需要创建一个回调函数并在其中调用remove。

使用此代码段 –

  $("article.post").not(".selected").fadeOut(500, function(){ $("article.post").not(".selected").remove(); }); 
 $("article.articles .thumb a").click(function() { $(this).parent().parent().addClass("selected"); $("article.post").not(".selected").fadeOut(500, function(){ setTimeout(function(item){ jQuery(item).remove(); }, 1500, $(this)); }); $('#stream').isotope('reLayout'); });