jQuery 中的 animate()方法函数

首页 / jQuery入门教程 / jQuery 中的 animate()方法函数

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

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

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

这将产生以下输出-

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

机器学习40讲 -〔王天一〕

算法面试通关40讲 -〔覃超〕

Linux实战技能100讲 -〔尹会生〕

Swift核心技术与实战 -〔张杰〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

物联网开发实战 -〔郭朝斌〕

如何讲好一堂课 -〔薛雨〕

零基础GPT应用入门课 -〔林健(键盘)〕

手把手带你写一个 MiniTomcat -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)