我想检测我的所有 fadeOut
何时完成
我的fadeOut
在容器的所有项目上都是随机持续的。
每次淡出后,我都会删除项目,在所有项目fadeOut
之后放置一个新项目。这个新项目已隐藏,等待淡入
function fadeOutItem(){
$('div.wrapper').children('.item-box').each(function(){
$(this).fadeOut(Math.floor(Math.random() * 1300) + 200, function(){
$(this)[0].remove();
});
});
}
最佳答案
基本上,您需要知道您的包装器何时不再包含任何子级。您可以在 fadeOut
本身的回调函数中执行此操作:
function fadeOutItem(){
$('div.wrapper').children('.item-box').each(function(){
$(this).fadeOut(Math.floor(Math.random() * 1300) + 200, function(){
$(this).remove();
if ($('div.wrapper').children('.item-box').length === 0) {
// add new item
}
});
});
}
关于javascript - 在所有fadeOut之后调用一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24180759/