无限循环函数和动画过滤选择

jquery 动画选择器过滤 :animated

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

点击按钮时跟改运动中元素的颜色。$(“div:animated”)//选择动画

主要是下面这个无限循环有点意思。

定义一个函数animateIt,然后在slideToggle中回调这个函数

animateIt();是调用。