Code for Begginners

domingo, 27 de julio de 2008

Prototype using PeriodicalExecuter

This function let us to execute some task periodically, it takes two arguments, the function
wich will be executed and the interval in secconds between executions.

For example i will use it to display two images in a alternate manner, you could see the demo at here.

This is a simple example and we will improve it in the nexts posts.


var i = 0;

function changeImage() {
 if(i%2==0){
  new Effect.Fade('image1', { // the id of the element containing the image
  duration: 1,
  fps: 50,
  afterFinish: function() { new Effect.Appear('image2', {duration: 1, fps: 50, queue:'end'})}
  });
 }else{
  new Effect.Fade('image2', { // the id of the element containing the image  duration: 1,
  fps: 50,
  afterFinish: function() { new Effect.Appear('image1', {duration: 1, fps: 50, queue:'end'})}
  });
 }
 i++;
}
window.onload = new PeriodicalExecuter(changeImage, 10);

Etiquetas

Powered By Blogger