javascript - 在所有fadeOut之后调用一个函数

标签 javascript jquery

我想检测我的所有 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/

相关文章:

javascript - 用下拉列表替换文本框

javascript - 将正则表达式匹配到下一个特殊字符,同时允许空格

javascript - 当我更改 document.getElementById 时,Ajax 不起作用

javascript - IE 中的 jQuery append() 问题

javascript - 如何将表单输入传递到 javascript iframe URL?

javascript - 表单提交时未定义函数

jQuery 定时事件

javascript - 通过 OnClick 事件为图像添加动画

javascript - OwlCarousel2 动画点 onChange

javascript - ValidForm Builder - 如何向 addButton() 对象添加自定义功能