jquery sequence fadeOut and then remove

后端 未结 3 909
-上瘾入骨i
-上瘾入骨i 2021-02-05 13:37

I try $(\'somediv\').fadeOut.remove(); but it only remove it, bang... it dont wait for the nice fadeOut, and THEN remove

why.. how to respect fadeout, and t

3条回答
  •  失恋的感觉
    2021-02-05 14:40

    With jQuery chaining, one part of the chain doesn't wait for other parts to end if there's a time-based component. So when you want something to happen when another thing finishes, you'll need to use callbacks. In this case, you call fadeOut() with a parameter for what function to run when it's done. Like so:

    $('#somediv').fadeOut(function(){ $(this).remove(); })};

    So when fadeOut() is done (and you can add a leading parameter that dictates how long that'll take, either in miliseconds or 'fast', 'normal', or 'slow'), it'll call the function, which does the remove().

提交回复
热议问题