开发者

How do I make fadeOut blocking in JQuery?

开发者 https://www.devze.com 2023-01-02 08:03 出处:网络
Pretty much as the question says, I have some code running on an interval: $(\"#blah\").fadeOut(2000);

Pretty much as the question says, I have some code running on an interval:

$("#blah").fadeOut(2000);
$("#blah2").fadeIn(2000);

I'd like to fadeOut, then fadeIn, rather than have both going simultaneously. Is there an e开发者_如何学运维asy way?


$("#blah").fadeOut(2000);
$("#blah2").delay(2000).fadeIn(2000);

Or:

$("#blah").fadeOut(2000, function(){
    $("#blah2").fadeIn(2000);
});


You need to make use of the callback functionality to ensure, that the animation completes before calling another. Looks like:

$('#blah').fadeOut(2000, function(){
    $('#blah2').fadeIn(2000);
});

see. .fadeOut()


$('#blah').fadeOut(2000, function(){
    $("#blah2").fadeIn(2000);
});

As explained in the documentation:

.fadeOut( [ duration ], [ callback ] )

duration: A string or number determining how long the animation will run.

callback: A function to call once the animation is complete.


$("#blah").fadeOut(2000);
setTimeout('$("#blah2").fadeIn(2000);', 2000);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号