简体   繁体   中英

jQuery wait till function is executed

I'm trying to call 2 functions. The first function includes a jQuery effect. The second function (in this case is a jQuery effect), but may only execute if the first function is executed (and finished). Can someone help me out? Thanks!

Fox example: http://jsfiddle.net/fNH2u/1/

function hideSecond(){
    $("#second").hide("slow");
}

$("#first").click(function(){
    hideSecond();
    $(this).hide("fast");
});

and the HTML:

<div id="first">
    first
</div>
<div id="second">
    second
</div>

The function I want to call does more than just that jQuery effect. This is just an example. Putting the 2 functions together is not really what I'm looking for.

You will need to use a callback here.

function hideSecond(callback){
    $("#second").hide("slow", callback);
}

$("#first").click(function(){
    hideSecond(function() {
       $(this).hide("slow");
    });
});

尝试在[complete]参数中使用.animate()和回调函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM