Jquery-effect-animate

提供:Dev Guides
移動先:案内検索

jQueryエフェクト-animate()メソッド

説明

  • animate()*メソッドは、一連のCSSプロパティのカスタムアニメーションを実行します。

構文

このメソッドを使用するための簡単な構文は次のとおりです-

selector.animate( params, [duration, easing, callback] );

パラメーター

このメソッドで使用されるすべてのパラメーターの説明は次のとおりです。

  • params -アニメーションが移動するCSSプロパティのマップ。
  • duration -これは、アニメーションの実行時間を表すオプションのパラメーターです。
  • easing -これは、遷移に使用するイージング関数を表すオプションのパラメーターです。
  • callback -これは、アニメーションが完了したときに呼び出す関数を表すオプションのパラメーターです。

以下は、このメソッドの使用方法を示す簡単な例です-

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript"
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>

      <script type = "text/javascript" language = "javascript">

         $(document).ready(function() {

            $("#out").click(function(){
               $("#block").animate({
                  width: "70%",
                  opacity: 0.4,
                  marginLeft: "0.6in",
                  fontSize: "3em",
                  borderWidth: "10px"
               }, 1500 );
            });

            $("#in").click(function(){
               $("#block").animate({
                  width: "100",
                  opacity: 1.0,
                  marginLeft: "0in",
                  fontSize: "100%",
                  borderWidth: "1px"
               }, 1500 );
            });

         });
      </script>

      <style>
         div {background-color:#bca; width:100px; border:1px solid green;}
      </style>
   </head>

   <body>
      <p>Click on any of the buttons</p>

      <button id = "out"> Animate Out </button>
      <button id = "in"> Animate In</button>

      <div id = "block">Hello</div>
   </body>
</html>

これにより、次の結果が生成されます–