Ver Mensaje Individual
  #3 (permalink)  
Antiguo 16/07/2010, 16:01
Avatar de stock
stock
 
Fecha de Ingreso: junio-2004
Ubicación: Monterrey NL
Mensajes: 2.390
Antigüedad: 19 años, 10 meses
Puntos: 53
Respuesta: SlideShow [duda]

mmmmm..... rayos!! O_o

pufff..... por donde comenzar, bueno van mis consejos:

1.- Encapsula tu código
2.- Utiliza correctamente el scope
3.- Utiliza prototipos (clases)
4.- No "hardcodees" las imágenes que quieres utilizar
5.- Utiliza correctamente el setTimeout
6.- No escribas código solo para IE

Tomando en cuenta esos consejos te pongo un pequeño ejemplo para darte una idea:

Código Javascript:
Ver original
  1. var Slideshow = function(options){
  2.      this.images = options.images;
  3.      this.duration = options.duration;
  4.      this.speed = options.speed;
  5.  
  6.      this.loadImages();
  7.      this.start();
  8. }
  9.  
  10. Slideshow.prototype = {
  11.      loadImages   : function(){
  12.           var p = this.images.length,
  13.                 preLoad = [];
  14.            for (var i = 0; i < p; i++) {
  15.                var img = new Image();
  16.                img.src = this.images[i];
  17.                preLoad.push(img);
  18.           }
  19.      },
  20.  
  21.      start   : function(){
  22.           var me = this;
  23.           this.j = 0;
  24.           this.thread = setInterval(function(){
  25.                me.run.call(me,me.j++);
  26.           },this.speed);
  27.      },
  28.  
  29.       run   : function(){
  30.           //aqui el código de animación
  31.           //te lo dejo de tarea :)
  32.  
  33.           if(this.j > this.images.length){
  34.                //ya terminó!
  35.                this.stop();
  36.           }
  37.       },
  38.  
  39.       stop   : function(){
  40.           clearInterval(this.thread);
  41.           this.j = 0;
  42.       }
  43. }
  44.  
  45.  
  46.  
  47. window.onload = function(){
  48.      
  49.      var slide1 = new Slideshow({
  50.           images    : ["images/image1.jpg","images/image2.jpg","images/image3.jpg"],
  51.           speed      : 2500,
  52.           duration  : 3
  53.      });
  54.  
  55.  
  56.      var slide2 = new Slideshow({
  57.           images    : ["images/image4.jpg","images/image4.jpg","images/imageN.jpg"],
  58.           speed      : 2500,
  59.           duration  : 3
  60.      });
  61.  
  62.  
  63. }


Por ultimo te aconsejo estar atento al desafío que se esta llevando acabo aqui en el foro de javascript: http://www.forosdelweb.com/f13/nuevo...agenes-822449/

Los participantes haremos un Slideshow con transiciones interesantes :)

Saludos

PD: No he probado el código, espero y te de una idea