这里有更详细的讲解呵呵
http://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html
自由落体
<p>横向系数:<input id="hp" type="text" value="0.1" /> (0-1)</p> <p>纵向系数:<input id="vp" type="text" value="0.6" /> (0-1)</p> <p>速度:<input id="sp" type="text" value="30" />(20-1000) <input type="button" value="demo" onclick="demo(document.getElementById('hp').value, document.getElementById('vp').value, document.getElementById('sp').value)" /></p> <div style="margin-left:600px;"> <div id="fall" style="width:30px; height:30px; background:#f90; position:relative; right:0px; bottom:40px"></div> </div> <script type="text/javascript"> var i = null; function demo(hp,vp,sp) { var f=document.getElementById('fall'); f.style.right='0px'; f.style.bottom='40px'; i&&clearInterval(i); var h=1,v=1,hp=(hp>0&&hp<1)?hp:0.2,vp=(vp>0&&vp<1)?vp:0.5,sp=(sp>20 || sp<1000)?sp:30; i=setInterval(function(){ if(f){ var r=parseInt(f.style.right)+h,b=parseInt(f.style.bottom)-v; f.style.right=r+'px'; f.style.bottom=b+'px'; if(r>1000)clearInterval(i); if(b>-210){ v+=2 } else { h=(v>0)?v*hp:0; v*=(v>0)?-1*vp:0 } } },sp); } </script>
提示:您可以先修改部分 代码再运行
抛物运动
<!doctype html> <html> <head> <meta charset="utf-8" /> <style type="text/css"> *{padding:0;margin:0;} body{font-size:13px;padding:10px;} p{margin:2px;} .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> <h3>模拟重力状态下的抛物运动(假使1px==1mm)</h3> <p>横向初速度:<input id="Vx" type="text" value="2" />px/ms</p> <p>纵向初速度:<input id="Vy" type="text" value="-2" />px/ms</p> <p>重力加速度:<input id="a" type="text" value="0.0098" />px/平方ms</p> <p>(如果这个加速度是一个随时间变化的值,就能达到其他非匀加速运动的效果了。)</p> <p>单位时间:<input id="t" type="text" value="10" />(记录运动的时间间隔) <p><input type="button" value="演示" onclick="demo(document.getElementById('Vx').value, document.getElementById('Vy').value, document.getElementById('a').value, document.getElementById('t').value)"/></p> <body> <div class="wrap"> <div id="fall">o</div> </div> </body> <script type="text/javascript"> function demo(x,y,a,t) { 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); } </script>
这东西强呀。
我又回来啦,关注贵站很久了,博客的访问量大吗?
这个不错,我收藏了,谢谢你.. 这是我的博客,欢迎回访: http://www.jmeii.com/haoqi/index.html
效果很不错 、赞!!
传说中的纯技术呀
很强!!!顶一个
Name (required)
Mail (will not be published) (required)
Website
天气骤冷,大家该南飞的南飞,该换毛的换毛,该冬眠的冬眠了.
这东西强呀。
我又回来啦,关注贵站很久了,博客的访问量大吗?
这个不错,我收藏了,谢谢你..
这是我的博客,欢迎回访:
http://www.jmeii.com/haoqi/index.html
效果很不错 、赞!!
传说中的纯技术呀
很强!!!顶一个