周伟东的博客!
懂得放弃,才会有新的收获!
Home
blog
About Me
Javascript摸拟自由落体与上抛运动
By weisnet On
2010-05-01
At 11:30 View:862
XML/HTML
<!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
runat
="server"
>
<title
>
模拟自由落体与上抛运动
</title
>
<script
type
="text/javascript"
>
var $ = function(el) { return document.getElementById(el); };
function LuoRun()
{
this.
h
= 0;
this.
s
= 0;
this.
g
= 9.8;
this.
isup
= false;
this.
rh
= 0;
this.
t
= 0;
this.
timer
= null;
this.
mt
= 0;
this.
top
= 0;
this.
left
= 0;
this.
id
= null;
}
LuoRun.prototype.
Po
= function(obj) {
this.left += 0.3;
obj.style.
left
= (this.left)+'px';
if (!this.isup) {
if (this.
t
="=" 0)
{
this.
top
= obj.offsetTop;
this.
h
= 570 - 22 - this.top;
this.
mt
= Math.sqrt(2*this.h/(this.g*100));
//alert(mt+' '+isup+' '+t)
}
this.t+="0.01;"
if (this.t
>
= this.mt)
{
this.
t
= this.mt;
this.
rh
= (1/2)*this.g*this.t*this.t*100;
this.
s
= this.g*this.t*100;
obj.style.
top
= (this.rh+this.top)+'px';
//
t
= 0;
this.
s
= this.s-50
>
0 ? this.s-50 : 0;
this.
isup
= true;
this.
t
= 0;
}
else
{
this.
rh
= (1/2)*this.g*this.t*this.t*100;
this.
s
= this.g*this.t*100;
obj.style.
top
= (this.rh+this.top)+'px';
}
} else { //up
//return;
if (this.
s
="=" 0) {
clearInterval(this.timer);
this.id.parentNode.removeChild(this.id);
return;
}
if (this.
t
="=" 0) {
this.
h
= this.s*this.s/(2*this.g*100);
this.
mt
= this.s/(this.g*100);
this.
top
= obj.offsetTop;
//alert(mt+' '+isup+' '+t)
}
this.t+="0.01;"
if (this.t
>
="this.mt)" {
this.t = this.mt;
this.rh = this.s*this.t - (1/2)*this.g*this.t*this.t*100;
obj.style.top = (this.top - this.rh)+'px';
this.s = 0;
this.isup = false;
this.t = 0;
}else {
this.rh = this.s*this.t - (1/2)*this.g*this.t*this.t*100;
obj.style.top = (this.top - this.rh)+'px';
}
}
}
LuoRun.prototype.Go = function(obj) {
var self = this;
if (obj ="=" null)
obj = $('box');
self.timer = setInterval(function() {
self.Po(obj);
if (self.h
<
="0)" {
clearInterval(self.timer);
self.id.parentNode.removeChild(self.id);
}
},10);
}
document.onmousedown = function(e) {
e = e?e:window.event;
var crtDiv = document.createElement('div');
crtDiv.style.position = 'absolute';
crtDiv.style.left = e.clientX + 'px';
crtDiv.style.top = e.clientY + 'px';
crtDiv.style.background = '#333';
crtDiv.style.width = '22px';
crtDiv.style.height = '22px';
document.body.appendChild(crtDiv);
crtDiv.innerHTML = ' ';
var C = new LuoRun();
C.left = e.clientX;
C.id = crtDiv;
document.onmouseup = function() {
document.onmousemove = null;
window.setTimeout(function() { C.Go(crtDiv); },1000);
}
}
</script
>
<style
type
="text/css"
>
td,body {font-size:12px;}
.css1 {width:240px;display:table;position:absolute;left:20px;top:20px;border:1px solid green;background:#CAF4BD;line-height:18px;padding:3px;}
.css2 {width:900px;height:22px;border-top:1px solid #333;position:absolute;top:570px;left:60px;}
</style
>
</head
>
<body
>
<form
id
="form1"
>
<div
class
="css1"
>
名称:Javascript摸拟自由落体与上抛运动!
<br
/>
作者:Gloot
<br
/>
邮箱:glootz@gmail.com
<br
/>
QQ:345268267
<br
/>
网站:www.weiseditor.com
<br
/>
操作:在页面不同地方点几下
</div
>
<div
id
="line"
class
="css2"
>
</div
>
</form
>
</body
>
</html
>
·上一篇:
简单易懂的C#委托与事件
·下一篇:
简单易懂的MS sql 2005 表达式分区
for this post
gloot
Says:
2010-05-15 13:21
查看实例
http://www.weiseditor.com/javascript/zylt.htm
Leave a Reply
首页
[1]
尾页
总共 1条记录.
请先
登陆
还没帐号
Hot Posts
windows2003 sp2 IIS .
ajax跨域访问(cross-d .
再谈firefox 、IE下 h .
Weiseditor 在线文本编 .
动态创建JSON节点 .
Firefox 下的 outerHT .
Friend links
码农的园子
Ajan的博客