:animated Selector


animated selector

描述: 选择所有正在执行动画效果的元素.

  • 添加的版本: 1.2jQuery( ":animated" )

注意:  如果您使用一个自定义的jQuery绑定一个没有效果模块:animated选择器会抛出一个错误。

Additional Notes:(其他注意事项:)

  • 因为:animated 是一个 jQuery 延伸出来的选择器,并不是的CSS规范的一部分,使用:animated 查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了当使用:animated 的时候在现代浏览器上获得更佳的性能,首先使用纯CSS选择器选择元素,然后使用.filter(":animated").

例子:

改变正在执行动画的 div 的颜色。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<head>
<style>
div { background:yellow; border:1px solid #AAA; width:80px; height:80px; margin:0 5px; float:left; }
div.colored { background:green; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button id="run">Run</button>
<div></div>
<div id="mover"></div>
<div></div>
<script>
$("#run").click(function(){
$("div:animated").toggleClass("colored");
});
function animateIt() {
$("#mover").slideToggle("slow", animateIt);
}
animateIt();
</script>
</body>
</html>

Demo: