感觉这样写有点烦,有更简洁的办法没?比如用判断语句?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery动画特效</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<style >
div{
position:absolute;
top:200px;
width:50px;
height:50px;
background-color:red;
color:white;
border-radius:20px;
text-align:center;
line-height:20px;
left:50px;
}
</style>
<body>
<input id="left" type="button" value="左移" />
<input id="right" type="button" value="右移" />
<div><font></font></div>
<script>
$(function(){
var $timel=0;
var $timer=0;
$("#left").bind("click",function(){ ++$timel;
$("div").animate({
left:"+=50px"
},3000,function(){
$(this).animate({
width:'+=20px',
height:'+=20px'
},2000,function(){
$("font").html("第"+$timel+"次左移");
});
});
});
$("#right").bind("click",function(){
++$timer;
$("div").animate({
left:"-=50px"
},3000,function(){
$(this).animate({
width:'-=20px',
height:'-=20px'
},2000,function(){
$("font").html("第"+$timer+"次右移");
});
});
});
});
</script>
</body>
</html>