无涯教程-jQuery - animate()方法函数

93 阅读1分钟

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

animate( params, [duration, easing, callback] ) - 语法

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

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

  • params      -  动画将朝其移动的CSS属性图。

  • duration    -  这是可选参数,表示动画将运行多长时间。

  • easing        -  这是可选参数,表示用于过渡的缓动功能。

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

animate( params, [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>

这将产生以下输出-

参考链接

www.learnfk.com/jquery/effe…