[Javascript] Firing up a function at the end of an event

Terry Riegel riegel at clearimageonline.com
Fri May 25 11:29:14 CDT 2007


Hello All,

Is there a way to have a function call another function when it is  
done? I have a fadeIn and a fadeOut function that takes place over  
time. I would like to have it call a passed function when it  
finishes. I have listed my function below.


function fadeIn (id,duration,steps,currstep) {
   stepDuration = Math.round(duration/steps) ; // Value is in  
miliseconds.
   obj = dd.elements[id];
   obj.setOpacity(1-(1/steps)*currstep);
   currstep --;
	if(currstep>=0){
	 setTimeout('fadeIn("'+id+'",'+duration+','+steps+','+currstep 
+')',stepDuration);
	 }
     else
      {dd.elements[id].show();
      }
   return;
}


I would like to have it work something like this...


function fadeIn (id,duration,steps,currstep,MYFINISHINGFUNCTION) {
   stepDuration = Math.round(duration/steps) ; // Value is in  
miliseconds.
   obj = dd.elements[id];
   obj.setOpacity(1-(1/steps)*currstep);
   currstep --;
	if(currstep>=0){
	 setTimeout('fadeIn("'+id+'",'+duration+','+steps+','+currstep 
+')',stepDuration);
	 }
     else
      {dd.elements[id].show();
       MYFINISHINGFUNCTION;
      }
   return;
}


I would call it something like...


fadeIn("currentslide",500,10,10,swapimage(a,b) );


Is this possible? If so what would be the proper syntax for such a  
convention




More information about the Javascript mailing list