2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

addClassから遅延後にremoveClassしたい

Last updated at Posted at 2017-10-12

CSSのtransitionを動作させるために、HTMLのclassを付け替えることをしばしばやることがあると思う。その付けたclassを指定時間後に消したいというケースがあった。

#やっつけ(失敗例)

$('div').addClass('hoge').delay(1000).removeClass('hoge');

これだと狙い通りに動かない。addとremoveが一瞬で行われる。delayはアニメーションでしか有効ではない。

#queueを使ってできるらしい

$('div').addClass('hoge').delay(1000).queuefunction(next){
  $(this).removeClass('hoge');
  next();
};

遅延後(1秒後)にremoveClassしてくれる。

2
3
0

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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?