<style>
.box{
width: 100px;
height: 100px;
background-color: red;
position: absolute;
left: 0px;
top: 0px;
}
</style>
<div class="box"></div>
<script>
var box=document.querySelector(".box")
function move(ele,target){
let left=parseInt(getComputedStyle(ele)["left"]);
let top=parseInt(getComputedStyle(ele)["top"]);
// console.log(left,top);
let speed=1;
setTimeout(()=>{
left+=speed;
top+=speed;
if(target===left){
console.log("移动完成");
}else{
ele.style.left=left+"px";
ele.style.top=top+"px";
move(box,300);
}
})
}
move(box,300);
用物理上力的知识可实现多个不同角度的移动。