trying to make some divs fadeOut and then be removed

六月ゝ 毕业季﹏ 提交于 2019-12-02 04:12:35

问题


I'm trying to make some divs fadeOut and then be removed.

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

But the divs are removed right away without fading.

What am I doing wrong?


回答1:


you can use fadeOut() callback function which is executed after fade effect is complete.

.fadeOut( [duration] [, callback] )

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

or:

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



回答2:


You are not waiting for the div to fade out before removing it. You need to create a callback function and call remove inside it.

Use this Snippet-

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


来源:https://stackoverflow.com/questions/11480177/trying-to-make-some-divs-fadeout-and-then-be-removed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!