metanohi-misc-subsites/old-projects/x/gravity.htm

94 lines
1.6 KiB
HTML

<!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>JS Gravity</title><style type='text/css'>
body {
margin:0;
padding:0;
overflow:hidden;
}
div {
position:absolute;
width:50px;
height:50px;
background:#000;
}
</style><script type='text/javascript'>
verticalspeed=2
horizontalspeed=15
spd=0
f=true
r=true
function getwh() {
if (self.innerHeight) {
h=self.innerHeight
w=self.innerWidth
}
else if (document.documentElement && document.documentElement.clientHeight) {
h=document.documentElement.clientHeight
w=document.documentElement.clientHeight
}
else if (document.body) {
h=document.body.clientHeight
w=document.body.clientWidth
}
}
function gravity() {
getwh()
ah=h-50
aw=w-50
//document.title=y+" "+ah+" "+spd
if (y<ah || spd>-1) {
if (f) {
spd+=verticalspeed
y+=spd
if (y<ah) b.style.top=y+"px"
else {
b.style.top=ah+"px"
spd-=verticalspeed
f=false
horizontalspeed=horizontalspeed/1.1
}
}
else {
spd-=verticalspeed
y-=spd
if (y>ah) y=ah
if (spd>0 && y<=ah) b.style.top=y+"px"
else f=true
}
if (r) {
x+=horizontalspeed
if (x<aw) b.style.left=x+"px"
else {
r=false
horizontalspeed=horizontalspeed/1.2
}
}
else {
x-=horizontalspeed
if (x>0) b.style.left=x+"px"
else {
r=true
horizontalspeed=horizontalspeed/1.2
}
}
}
t=setTimeout("gravity()",50)
}
function load() {
getwh()
y=0
x=-50
b=document.createElement("div")
b.style.top=y+"px"
b.style.left=x+"px"
document.body.appendChild(b)
gravity()
}
window.onload=load
</script></head><body></body></html>