当前位置: 首页 > 文档资料 > jQuery 入门教程 >

animate(params, [duration, easing, callback] )

优质
小牛编辑
124浏览
2023-12-01

描述 (Description)

animate( )方法执行一组CSS属性的自定义动画。

语法 (Syntax)

以下是使用此方法的简单语法 -

<i>selector</i>.animate( params, [duration, easing, callback] );

参数 (Parameters)

以下是此方法使用的所有参数的说明

  • params - 动画将移向的CSS属性的映射。

  • duration - 这是表示动画运行duration可选参数。

  • easing - 这是可选参数,表示用于转换的缓动函数。

  • callback - 这是一个可选参数,表示动画完成后要调用的函数。

例子 (Example)

以下是一个简单的例子,简单地显示了这种方法的用法 -

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