When
The $.when() method
Now, using our test page as an example, I'll show you the nifty $.when() method:
$.when(
$("article h3").hide(3000),
$("article img").slideUp(1000),
$("article p").fadeTo(2000, 0.1)
).then(() =>
$("article").slideUp(500)
).done(() =>
console.info("done")
).catch(() =>
console.error("fail :(")
)Let me explain what's happening — all animations start simultaneously, and when they all finish, the function we pass as an argument to the then() method gets called (one of two, depending on the outcome).
To make this "magic" work, $.when(), $.ajax(), and animate() all implement the Deferred interface. That's why we can use all the methods we explored in the previous chapter.
Last updated