:animated

$(':animated') 1.2追加

アニメーション中の要素を選択します。

注意事項

Effectsモジュールを除いたカスタムビルドで構築したjQueryを使用している場合は、:animatedを使用するとerrorをthrowします。

:animateはjQueryが独自に拡張した仕組みでCSSには存在しない概念です。 そのため、querySelectorAll()によって提供されるパフォーマンスを享受することが出来ません。 最高のパフォーマンスを出すためには、純粋なCSSセレクタのみを使用して要素を特定し、 それに対して.filter(":animated")を適用してください。

デモ

実行ボタンを押すと、アニメーション中のDIV要素のみ背景色を緑色に変更します。

<!DOCTYPE html>
<html>
<head>
<style>
  div { background:yellow; border:1px solid #AAA; width:80px; height:80px; margin:0 5px; float:left; }
  div.colored { background:green; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button id="run">実行</button>
<div></div>
<div id="mover"></div>
<div></div>
<script>
  $("#run").click(function(){
    $("div:animated").toggleClass("colored");
  });
  function animateIt() {
    $("#mover").slideToggle("slow", animateIt);
  }
  animateIt();
</script>
</body>
</html>

 Back to top

© 2010 - 2017 STUDIO KINGDOM