如何在许多元素上的fadeOut()之后调用函数 [英] How to call a function after a fadeOut() on many elements
问题描述
我有此代码:
$('.hotel_photo_select').fadeOut(500, function () {
alert("Now all '.hotel_photo_select are hidden'");
});
,并且我只想在 ALL .hotel_photo_select
被淡出(因此,隐藏)时调用该警报.
and I'd like to call that alert only when ALL .hotel_photo_select
are fadeOuted (so, Hidden).
我该怎么办?在我的代码中,第一个元素淡出后会调用警报...
How can I do it? With my code the alert is called after the first element is fadeout...
推荐答案
为此,您可以使用 promise()方法(文档页面上有一个很好的例子).
You can use the promise() method for this (the doc page has a good example for this).
.promise()方法返回动态生成的Promise,该Promise是 一旦将某种类型的所有动作绑定到集合,就解决了, 是否排队,已经结束.
The .promise() method returns a dynamically generated Promise that is resolved once all actions of a certain type bound to the collection, queued or not, have ended.
应用于您的示例应该是这样的:
Applied to your example should be something like this:
$.when($('.hotel_photo_select').fadeOut(500))
.done(function() {
alert("Now all '.hotel_photo_select are hidden'");
});
这篇关于如何在许多元素上的fadeOut()之后调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!