|
[RIA]一个小球自由落体运动的例子 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head>
<body><div id="ball_div" onclick="restart();" style="position:absolute;font-size:1px;width:20px; height:20px; z-index:100"><img src="ball.gif" /></div><script language="javascript">var radius=10;var stopPostionX=200;//球停止时中心的x坐标var stopPostionY=400;//球停止时中心的y坐标var damp=0.75;var g=1000;var t=0.0;var interval=0.01;var startPostionY=100;//球起始时中心的y坐标
var minV=damp*interval*g;var minS=5;
var currentPostionX=stopPostionX;//球停止时中心的x坐标var currentPostionY=startPostionY;//球停止时中心的y坐标
//var s=currentPostionY-stopPostionY;var standS=currentPostionY-stopPostionY;
var velocity0=0;var velocity=0;
var ball=document.getElementById("ball_div");function setPosition(x,y){ ball.style.left=(x-radius)+"px"; ball.style.top=(y-radius)+"px";}setPosition(currentPostionX,currentPostionY);
function calculatePostion(){ t+=interval; var currentS=standS+(velocity0+velocity)/2*t;//+0.5*g*t*t; velocity=velocity0+g*t; currentPostionY=parseInt(currentS)+stopPostionY;
if(Math.abs(velocity)<minV && Math.abs(currentS)<minS) { clearInterval(tid); currentPostionY=stopPostionY; } if(currentS>0) { standS=0; t=0; velocity0=velocity=-velocity*damp; } setPosition(currentPostionX,currentPostionY); //window.status=" V="+velocity;}var tid=setInterval("calculatePostion()",interval*1000);function restart(){clearInterval(tid);velocity0=velocity=-400-parseInt(500*Math.random());t=0;standS=0;tid=setInterval('calculatePostion()',interval*1000)}</script><div onclick="restart()" style="position:absolute; top:0px; left:0px; width:400px; height:410px; background-color:#999966; z-index:10"><input type="button" value="随机" onclick="restart()"/></div>
<div id="log"></div></body></html>
|
|
|
|  | .: 公告
| |
| « | November 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | | | |
| .: 我的分类(专题) | |  .: 最新日志 .: 最新回复
| | 
blog名称:up forever 日志总数:130 评论数量:274 留言数量:4 访问次数:1954584 建立时间:2006年5月25日 |
|  .: 留言板 |  .: 链接 |

|