87,914
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
#div1{width:0px; height:0px; background:#CCC; position:absolute; left:0px; top:0px;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script>
$(function() {
var color = ["#CCC", "#000", "#FF0"], i = 0, flag = false,
x = 0, y = 0, w = 500, h = 300,
div = $("#div1");
function animate(){
div.animate({left: 0, top: 0, width: w, height: h}, 1000, function(){
if(flag){
x = 0, y = 0;
}else{
x = w, y = h;
}
div.animate({ left: x, top: y, width:0, height:0}, 1000, next);
});
}
function next(){
i = ++i % color.length;
div.css("backgroundColor", color[i]);
flag = !flag;
animate();
}
animate();
})
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
简化了一下