metanohi-misc-subsites/projects/x/pgravity.htm

113 lines
2.3 KiB
HTML
Raw Normal View History

2011-08-02 19:57:57 +02:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3c.org/1999/xhtml">
<head>
<title>Poor JS Gravity</title>
<style type='text/css'>
body {
overflow:auto;
}
div {
background-color:#000;
position:absolute;
}
div.b {
background-color:#ccc;
}
</style>
<script type='text/javascript'>
function fc() { f+=1 }
function getwh() {
if (self.innerHeight) {
w=self.innerWidth
h=self.innerHeight
}
else if (document.documentElement && document.documentElement.clientHeight) {
w=document.documentElement.clientWidth
h=document.documentElement.clientHeight
}
else if (document.body) {
w=document.body.clientWidth
h=document.body.clientHeight
}
}
function movefigure() {
getwh()
for (i=0; i<f; i++) {
fy=h-figure[i][1]-figure[i][3]
nfy=h-figure[i][1]*speed-figure[i][3]
//document.title=Math.round(fy)+" "+Math.round(nfy)
if (nfy>0 && fy>0 && !figure[i][4]) {
figure[i][1]=(figure[i][1]+figure[i][5])*speed-figure[i][5]
figure[i][0].style.top=Math.round(figure[i][1])+"px"
}
else if (!(nfy>0) && fy>0 && !figure[i][4]) {
figure[i][0].style.top=(h-s)+"px"
}
else if (figure[i][4]) {
figure[i][1]=(figure[i][1]-figure[i][5]/3)/speed+figure[i][5]/3
figure[i][0].style.top=Math.round(figure[i][1])+"px"
document.title=figure[i][1]+" "+figure[i][5]
if (figure[i][1]<figure[i][5]) {
figure[i][4]=false
}
}
if (nfy<0 && !figure[i][4]) {
figure[i][4]=true
figure[i][1]=h-s
figure[i][5]=figure[i][5]+h/max*10
//figure[i][0].className="b"
}
}
mft=setTimeout("movefigure()",50)
}
function drawfigure(x,y,rs) {
getwh()
if (w>h)
s=h/max*rs
else
s=w/max*rs
s=Math.round(s)
x=Math.round(w/max*x)
y=Math.round(h/max*y)
figure[f]=new Array()
figure[f][0]=document.createElement("div")
figure[f][0].style.left=x+"px"
figure[f][0].style.top=y+"px"
figure[f][0].style.width=s+"px"
figure[f][0].style.height=s+"px"
figure[f][0].style.zIndex=f+1
bd.appendChild(figure[f][0])
figure[f][1]=y
figure[f][2]=x
figure[f][3]=s
figure[f][4]=false
figure[f][5]=y
figure[f][6]=x
fc()
}
function load() {
max=100
speed=1.02
figure=new Array()
f=0
bd=document.body
movefigure()
drawfigure(40,40,7)
}
window.onload=load
</script>
</head>
<body>
</body>
</html>