inoma-NOTE

自分のためのメモじゃ

animate完了後の処理、書き方2通り【jQuery】

地味に忘れちゃうのでメモ。

jQueryのanimateメソッドで、アニメーション完了後の動きを指定するとき、書き方が2通りある。

completeを使う場合

  $('.sample').stop().animate({
    width:'200px',
    height:'200px'
  },{
    duration:200,
    easing:'easeInBack',
    complete:function(){
      $(this).addClass('change');
    }
  });

省略して書く場合

  $('.sample').stop().animate({
    width:'200px',
    height:'200px'
  }, 200, 'easeInBack', function(){
    $(this).addClass('change');
  });

サンプル

See the Pen anime2 by inoma (@inoma) on CodePen.