设置功能完成后触发jQuery代码 [英] Set jQuery code to fire after function has completed

查看:97
本文介绍了设置功能完成后触发jQuery代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下功能(我从中间删除了对我的问题不重要的代码):

I have the following function (I've removed code from the middle that is not important to my question):

function shadowBoxRefresh(){
    $("#sb-nav-next, #sb-nav-previous").click(function(){
            $('#sb-container').addClass("visibility_stay");
            $('#sb-overlay').addClass("opacity_stay");
            Shadowbox.close();
            Shadowbox.clearCache();
            shadowBoxSetup();
            setTimeout("Shadowbox.open(c)", 400)
            $('#sb-container').removeClass("visibility_stay");
            $('#sb-overlay').removeClass("opacity_stay");
        }
    });
}

我的问题是,我需要这一部分:

My problem is, I need this part:

$('#sb-container').removeClass("visibility_stay");
$('#sb-overlay').removeClass("opacity_stay");

在之后触发 其余功能已完成.我想知道回调函数是否可以胜任这项工作,但是我对回调函数并不精通,不知道如何实现它.

to fire after the rest of the function has completed. I'm wondering if a callback would do the job, but I'm not versed well enough in callbacks to know how to implement it.

非常感谢您的帮助.

推荐答案

如果通过在该函数的其余部分之后"表示在Shadowbox.open(c)之后"发生0.4秒,则执行此操作:

If by "after the rest of the function" you mean, "after the Shadowbox.open(c)" that happens .4 sec later, then do this:

function shadowBoxRefresh(){
    $("#sb-nav-next, #sb-nav-previous").click(function(){
            $('#sb-container').addClass("visibility_stay");
            $('#sb-overlay').addClass("opacity_stay");
            Shadowbox.close();
            Shadowbox.clearCache();
            shadowBoxSetup();
            setTimeout(function () {
                Shadowbox.open(c);
                $('#sb-container').removeClass("visibility_stay");
                $('#sb-overlay').removeClass("opacity_stay");
            }, 400);
        }
    });
}

这篇关于设置功能完成后触发jQuery代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆