Executing jQuery Fadeout () callback function synchronously

I'm trying to do something like this

01 ...do some heavy duty stuff

02   //delete some rows <tr>
03 $('...').fadeOut(function () {
04     $(this).remove();
05 }); 

06 ...do some heavy duty stuff
07 ...add some rows <tr>

However, the fadeOut callback function does not work immediately. Because of this, my logic of adding new lines after they are deleted does not work properly. I know that I can put the code on lines 6 and 7 inside the callback, but I do not want to do this because the callback has a lot of logic and receives the call from other places.

Is there a way to force fadeout () to complete its callback before it reaches line 6?

+3
source share
3 answers

, , , , .

fadeOut, ( commonCallback), , , :

// ...do some heavy duty stuff

//delete some rows <tr>
$('...').fadeOut(function () {
    commonCallback();

    // ...do some heavy duty stuff
    // ...add some rows <tr>
}); 
+2

- setTimeout() , , fadeOut().

$('...').fadeOut(function () {
     $(this).remove();
}, 600); 

setTimeout(function() {
    // place your code that should wait
    //   for the fadeOut to complete
    //   inside here
}, 600);

, 600ms.

, setTimeout, 600ms .

+1

, ? , , .

, . . , , 6 7 . :

$('...').fadeOut(function() {
   doRemoveAndLotsOfCoolStuff();
   doLines6and7();
});
0
source

Source: https://habr.com/ru/post/1763475/


All Articles