2

我正在尝试使一些 div 淡出然后被删除。

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

但是 div 会立即被删除而不会褪色。

我究竟做错了什么?

4

3 回答 3

1

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

.fadeOut( [持续时间] [, 回调] )

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

或者:

$("article.post").not(".selected").fadeOut(500).delay(2000).queue(function(){
   $(this).remove()
})
于 2012-07-14T01:12:01.743 回答
0
$("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');
});
于 2012-07-14T01:12:22.700 回答
0

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

使用这个片段-

   $("article.post").not(".selected").fadeOut(500, function(){
                            $("article.post").not(".selected").remove();
                        });
于 2012-07-14T01:14:46.010 回答