console
window.onload=function() {
var oBtn=document.getElementById('btn1');
oBtn.onclick=function() {
startMove(300);
}
}
var timer=null;
function startMove(iTarget) {
var oDiv=document.getElementById('div1');
clearInterval(timer);
timer=setInterval( function() {
var speed=(iTarget-oDiv.offsetLeft)/10;
oDiv.style.left=oDiv.offsetLeft+speed+'px';
document.title=oDiv.offsetLeft+","+speed;
},30);
}
<input id="btn1" type="button" value="开始运动">
<div id="div1"></div>
<div id="div2"></div>
#div1 {width: 100px; height: 100px; background: red; position: absolute; top: 50px; left: 0px;}
#div2 { width: 1px; height: 300px; background: black; position: absolute; top: 50px; left: 300px; }
#btn1 {margin: 0;}