jQuery 中的 animate()方法函数

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

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

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

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

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

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

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

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

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

animate( params, [duration, easing, callback] ) - 示例

以下是一个简单的示例,简单说明了此方法的用法-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/effect-animate.html

来源:LearnFk无涯教程网

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

这将产生以下输出-

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

技术教程推荐

持续交付36讲 -〔王潇俊〕

代码精进之路 -〔范学雷〕

MySQL实战45讲 -〔林晓斌〕

检索技术核心20讲 -〔陈东〕

人人都用得上的写作课 -〔涵柏〕

说透5G -〔杨四昌〕

Vue 3 企业级项目实战课 -〔杨文坚〕

给程序员的写作课 -〔高磊〕

徐昊 · AI 时代的软件工程 -〔徐昊〕

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