代码:

 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1 {
width: 100px;
height: 100px;
background: #ff4b46;
position: absolute;
left: 100px;
top: 50px;

}
</style>
<script>

function startMove(){
setInterval(function(){
var oDiv=document.getElementById("div1");
var speed=(1000-oDiv.offsetLeft)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
oDiv.style.left=oDiv.offsetLeft+speed+"px";
document.title=oDiv.offsetLeft+','+speed;
},30);
}



</script>
</head>
<body>
<input type="button" value="开始运动" onclick="startMove()">
<div id="div1">


</div>

</body>
</html>

 

运行结果:

  初始界面:

运动——物体运动越来越慢直到停止

  点击鼠标之后界面:

运动——物体运动越来越慢直到停止

相关文章:

  • 2021-07-30
  • 2021-05-08
  • 2021-05-20
  • 2021-04-18
  • 2021-10-20
  • 2022-01-11
  • 2022-01-02
猜你喜欢
  • 2021-11-05
  • 2021-12-15
  • 2022-03-09
  • 2022-12-23
  • 2021-09-19
  • 2021-11-15
  • 2022-12-23
相关资源
相似解决方案