问题
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