How to call a function after a fadeOut() on many elements

后端 未结 2 1879
-上瘾入骨i
-上瘾入骨i 2020-12-25 13:32

I have this code :

$(\'.hotel_photo_select\').fadeOut(500, function () {
    alert(\"Now all \'.hotel_photo_select are hidden\'\");
});

and

2条回答
  •  囚心锁ツ
    2020-12-25 13:38

    You can use the promise() method for this (the doc page has a good example for this).

    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'");
    });
    

提交回复
热议问题