【问题标题】:trying to make some divs fadeOut and then be removed试图让一些 div 淡出然后被移除
【发布时间】:2012-07-14 01:08:51
【问题描述】:

我正在尝试让一些 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 会立即被移除而不会褪色。

我做错了什么?

【问题讨论】:

  • delay() 作用于动画队列,remove()不在该队列中,所以没有效果。不过,发布的答案应该对您有用。

标签: jquery fadeout


【解决方案1】:

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

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

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

或:

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

【讨论】:

  • @Gab 你能发布 HTML 部分吗?
【解决方案2】:

在移除 div 之前,您无需等待它淡出。你需要创建一个回调函数并在里面调用remove。

使用此代码段-

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

【讨论】:

    【解决方案3】:
    $("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');
    });
    

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多