您的位置:首页 > Web前端 > JavaScript

js抛物线

2016-05-20 17:09 447 查看
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.wrap {
position: relative;
width: 1000px;
height: 550px;
margin: 0 auto;
border: 1px solid #ccc;
margin-top: 50px;
}
#fall {
width: 20px;
font-size: 1px;
height: 20px;
background: #000;
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<input type="button" value="演示" onclick="demo()">;
<div class="wrap">
<div id="fall">o</div>
</div>
<script>
function demo() {
var x, y, a,t;
x=2;
y=-2;
a=0.0098;
t=10;
var f=document.getElementById('fall');
var Vx=parseInt(x),
Vy=parseInt(y),
g=a,
t=parseInt(t),
h=0,l=0,Sx=0,Sy=0;
var i=setInterval(function(){
if(f){
Sx+=Vx*t;
l=Sx;
Vy+=g*t;
h+=Vy*t;
f.style.left=l+'px';
f.style.top=h+'px';
if(h>500||l>900)clearInterval(i);
}
},t);
}
//  demo(2,-2,0.0098,10);

</script>
</body>
</html>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: