<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
</style>
</head>
<body>
<div style="width:100px;height:100px;background:red;position:absolute;left:500px;"></div>
<button id="btn" style="margin-top:150px;">121</button>
<span style="position:absolute;left:300px;height:100px;width:1px;background:black;top:0"></span>
<script>
var oDiv = document.getElementsByTagName('div')[0];
var oBtn = document.getElementById('btn');
var timer = null;
oBtn.onclick = function(){
starMove(oDiv,300)
}
function starMove(dom,target){
clearInterval(timer);
var iSpeed = null;
timer = setInterval(function(){
iSpeed = (target - oDiv.offsetLeft) / 7
iSpeed = iSpeed>0?Math.ceil(iSpeed) : Math.floor(iSpeed)
if(oDiv.offsetLeft == target){
clearInterval(timer);
}else{
oDiv.style.left = oDiv.offsetLeft + iSpeed + 'px'
}
})
}
</script>
</body>
</html>