SOURCE

console 命令行工具 X clear

                    
>
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;
			 //speed=speed>0?Math.ceil(speed):Math.floor(speed);
			oDiv.style.left=oDiv.offsetLeft+speed+'px';
		    document.title=oDiv.offsetLeft+","+speed;
		    //alert(oDiv.style.left);//最后弹出的值为296.4px
	    },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;}