jQuery动画效果实现

时间:2022-11-30 18:52:56
 <!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" type="text/javascript"></script>
<style>
div{
position:absolute;
top:50px;
left:200px;
height:50px;
width:50px;
border:1px solid red;
}
</style>
</head>
<body>
<div></div>
<input id="leftmove" type="button" value="左移"/>
<input id="rightmove" type="button" value="右移"/>
<script type="text/javascript">
$(function(){
$ltime=;
$rtime=;
$("#leftmove").bind("click",function(){//绑定元素事件
$ltime++;
$("div").animate({//调用animate制作移动动画
left:'-=50px'
},,function(){
$("div").html("左移"+$ltime+"次!");
});
});
$("#rightmove").bind("click",function(){
$rtime++;
$("div").animate({
left:'+=50px'
},,function(){
$("div").html("右移"+$rtime+"次!");
});
});
});
</script>
</body>
</html>