<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#div1{
width: 100px;
height: 100px;
background: red;
position: absolute;
}
</style>
<script>
window.onload=function(){
var oDiv=document.getElementById("div1");
var oInput=document.getElementById("input1");
var timer=null;
var iSpeed=0;
oInput.onclick=function(){
startMove();
}
function startMove(){
clearInterval(timer);
timer=setInterval(function(){
iSpeed+=3;
var T=oDiv.offsetTop+iSpeed;
if(T>document.documentElement.clientHeight-oDiv.offsetHeight){
T=document.documentElement.clientHeight-oDiv.offsetHeight;
iSpeed*=-1;
iSpeed*=0.75;
}
oDiv.style.top=T+"px";
},30)
}
}
</script>
</head>
<body>
<input type="button" value="开始运动" id="input1" />
<div id="div1"></div>
</body>
</html>