:animated 选择器
分类:选择器 > 基本筛选选择器 | 选择器 > jQuery扩展选择器
animated selector
描述:选择当选择器运行时,所有的正在动画进行中的元素。
加入于: 1.2
jQuery( ":animated" )注意:如果你使用了一个自定义jQuery,没有使用effects模块,则:animated选择器将抛出一个错误。
其它说明
- 因为
:animated是一个jQuery扩展,并不是CSS规范文档的一部分,所以使用:animated查询,就不能充分利用原生DOM提供的querySelectorAll()来提高性能。要想在使用:animated选择元素时获得最好的性能,首先用一个纯CSS选择器选中一个元素,然后使用.filter(":animated")作筛选。
示例
改变任何变动着的div的字色。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>animated demo</title>
<style>
div {
background: yellow;
border: 1px solid #AAA;
width: 80px;
height: 80px;
margin: 0 5px;
float: left;
}
div.colored {
background: green;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.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>
演示结果