gauri_agr
the code you are using is very old.
all modern browsers recognise getElementByID so I removed the obsolete alternatives.
also the code did not account for the image width and height.
DD should update the code as it is effective but among other things, makes all variables global(bad practice)
Code:
<!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" xml:lang="en" lang="en">
<head>
<title></title>
<script language="JavaScript1.2">
//Autumn leaves- by Kurt Grigg (kurt.grigg@virgin.net)
//Modified by Vic Phillips (19-August-2009)
var ImgAry=[];
ImgAry[0]="http://yogaforfun.netne.net/images/al.gif";
ImgAry[1]="http://yogaforfun.netne.net/images/bl.gif"
ImgAry[2]="http://yogaforfun.netne.net/images/cl.gif"
ImgAry[3]="http://yogaforfun.netne.net/images/dl.gif"
ImgAry[4]="http://yogaforfun.netne.net/images/el.gif"
ImgAry[5]="http://yogaforfun.netne.net/images/fl.gif"
// optional preload code
for (var SRCAry=[],z0=0;z0<ImgAry.length;z0++){
SRCAry[z0]=new Image();
SRCAry[z0].src=ImgAry[z0];
}
function AutumnLeaves(imgary,nu){
var p=zxcES('DIV',{position:'absolute',top:'0px',left:'0px'},document.body);
this.nu=nu||10;
this.imgs=[];
this.Ypos=[];
this.Xpos=[];
this.Speed=[];
this.Cstep=[];
this.Step=[];
for (var z0=0;z0<nu;z0++){
this.imgs[z0]=zxcES('IMG',{position:'absolute',top:'0px',left:'0px'},p);
this.imgs[z0].src=imgary[Math.floor(Math.random()*imgary.length)]
this.Ypos[z0] = Math.round(Math.random()*zxcWWHS()[1]);
this.Xpos[z0] = Math.round(Math.random()*zxcWWHS()[0]);
this.Speed[z0]= Math.random()*5+3;
this.Cstep[z0]=0;
this.Step[z0]=Math.random()*0.1+0.05;
}
this.Drop();
}
AutumnLeaves.prototype.Drop=function(){
var oop=this,wd=zxcWWHS();
for (var sx,sy,i=0; i <this.nu; i++){
sy = this.Speed[i]*Math.sin(90*Math.PI/180);
sx = this.Speed[i]*Math.cos(this.Cstep[i]);
this.Ypos[i]+=sy;
this.Xpos[i]+=sx;
if (this.Ypos[i] > wd[1]){
this.Ypos[i]=-60;
this.Xpos[i]=Math.round(Math.random()*wd[0]);
this.Speed[i]=Math.random()*5+3;
}
var img=this.imgs[i];
img.style.left=Math.min(wd[0],this.Xpos[i])-img.width+'px';
img.style.top=this.Ypos[i]+wd[3]-img.height+'px';
this.Cstep[i]+=this.Step[i];
}
this.to=setTimeout(function(){ oop.Drop(); },20);
}
function zxcWWHS(){
if (window.innerHeight) return [window.innerWidth-10,window.innerHeight-10,window.pageXOffset,window.pageYOffset];
else if (document.documentElement.clientHeight) return [document.documentElement.clientWidth-10,document.documentElement.clientHeight-10,document.documentElement.scrollLeft,document.documentElement.scrollTop];
return [document.body.clientWidth,document.body.clientHeight,document.body.scrollLeft,document.body.scrollTop];
}
function zxcES(ele,style,par,txt){
if (typeof(ele)=='string') ele=document.createElement(ele);
for (key in style) ele.style[key]=style[key];
if (par) par.appendChild(ele);
if (txt) ele.appendChild(document.createTextNode(txt));
return ele;
}
window.onload=function(){
var a=new AutumnLeaves(ImgAry,8)
}
//-->
</script></head>
<body>
<div style="height:1000px;" ></div>
</body>
</html>
Bookmarks