<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#div1{
width: 200px;
height: 200px;
background-color: #CCCCCC;
position: absolute;
top: 50px;
left: 0;
}
</style>
</head>
<body>
<input type="button" name="btn1" id="btn1" value="运动" />
<div id="div1">
</div>
<script src="js/tween.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var oDiv1 = document.getElementById("div1");
var oBtn = document.getElementById("btn1");
oBtn.onclick = function(){
// 参数1 : 当前时间
var t = 0;
// 参数2 : 初始位置(通常写0)
var start = 0;
// 参数3 : 结束位置(变化量)
var end = 600;
// 参数4 : 持续时间(次数)
var d = 50;
// 让div动起来
var timer = null;
clearInterval(timer);
timer = setInterval(function(){
// 每一次运动都会走一次
t++;
if(t == d){
clearInterval(timer);
}
oDiv1.style.left = Tween.Bounce.easeInOut(t, start, end - start, d) + 'px';
},20);
}
</script>
</body>
</html>