li923

JavaScript String 小球重力弹回

复制代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.box{
width: 50px;
height: 50px;
border-radius: 50%;
background:purple;
position: absolute;
top: 0;
left: 0;
}
.line{
width: 500px;
border: 1px solid #333;
position: absolute;
top: 450px;
left: 0;
}
</style>
</head>
<body>
<div class="box"></div>
<div class="line"></div>
</body>
<script type="text/javascript">
var obox=document.querySelector(".box");

var speed=5;//计步器
var target=400;//下落高度
document.onclick=function(){
setInterval(function(){
speed+=10;
var now=obox.offsetTop+speed;
if(now>=target){
now=target;
speed*=-1;//当小球到达底部停止,使他方向相反运动
speed*=0.9;//使小球有一定的速度

}
obox.style.top=now+"px";
},30)
}

</script>
</html>

复制代码

 

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-10
  • 2021-10-15
  • 2021-10-15
  • 2021-06-07
  • 2021-11-14
  • 2021-04-05
相关资源
相似解决方案