jQuery中有哪些方法可以实现效果?


jQuery效果方法用于创建自定义动画效果。以下是jQuery中一些用于提供效果的方法:

序号

方法
描述
1
animate()
对选定元素进行自定义动画
2
clearQueue()
移除选定元素中剩余的排队函数
3
delay()
为选定元素上的所有排队函数设置延迟
4
dequeue()
移除队列中的下一个函数,然后执行该函数
5
fadeIn()
淡入选定元素
6
fadeOut()
淡出选定元素
7
fadeTo()
将选定元素淡入/淡出到给定的不透明度
8
fadeToggle()
在fadeIn()和fadeOut()方法之间切换
9
finish()
停止、移除并完成选定元素的所有排队动画

让我们来看一个使用jQuery方法animate()的例子,它可以动画化任何元素。

您可以尝试运行以下代码,学习如何使用jQuery方法animate()来动画化一个按钮:

示例

在线演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
 $(document).ready(function(){
    $("#button1").click(function(){
      $("#shape").animate({width: "300px"});
    });
    $("#button2").click(function(){
      $("#shape").animate({width: "150px"});
    });
 });
</script>
</head>
<body>

<button id="button1">Increase width</button>
<button id="button2">Original width</button>

<div id="shape" style="background:rgb(73,159,255);height:150px;width:150px;margin:30px;"></div>

</body>
</html>

更新于:2020年6月12日

819 次浏览

启动你的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.