LoginSignup
69
65

More than 5 years have passed since last update.

jQueryでfadeOutの後にremove

Posted at

要素をフェードアウトした後に削除しようと、

sample.js
$(this).fadeOut('fast').remove();

としてみたところ、
フェードアウトせずにそのまま消えてしまった。

ちょっと調べてみると、処理を待つキューに入る処理と入らない処理があるとのこと。
エフェクト系は概ね入るようだけど、remove()はキューに入らない。
キューに入れるには.queue()を使う。

sample.js
$(this).fadeOut('fast').queue(function() {
  this.remove();
});

これでフェードアウトを待って削除できる。

69
65
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
69
65