如何使jQuery效果按顺序运行,而不是同时运行? [英] How to make jQuery effects run in sequence, not simultaneously?

查看:70
本文介绍了如何使jQuery效果按顺序运行,而不是同时运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jQuery中按顺序运行两个效果,而不是同时运行?以这段代码为例:

How do I have two effects in jQuery run in sequence, not simultaneously? Take this piece of code for example:

$("#show-projects").click(function() {
    $(".page:visible").fadeOut("normal");
    $("#projects").fadeIn("normal");
});

fadeOut和fadeIn同时运行,我如何让它们一个接一个地运行?

The fadeOut and the fadeIn run simultaneously, how do I make them run one after the other?

推荐答案

您可以为效果完成后运行的效果函数提供回调。

You can supply a callback to the effects functions that run after the effect has completed.

$("#show-projects").click(function() {
    $(".page:visible").fadeOut("normal", function() {
        $("#projects").fadeIn("normal");
    });
});

这篇关于如何使jQuery效果按顺序运行,而不是同时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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