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 originalvar Slideshow = function(options){
this.images = options.images;
this.duration = options.duration;
this.speed = options.speed;
this.loadImages();
this.start();
}
Slideshow.prototype = {
loadImages : function(){
var p = this.images.length,
preLoad = [];
for (var i = 0; i < p; i++) {
var img = new Image();
img.src = this.images[i];
preLoad.push(img);
}
},
start : function(){
var me = this;
this.j = 0;
this.thread = setInterval(function(){
me.run.call(me,me.j++);
},this.speed);
},
run : function(){
//aqui el código de animación
//te lo dejo de tarea :)
if(this.j > this.images.length){
//ya terminó!
this.stop();
}
},
stop : function(){
clearInterval(this.thread);
this.j = 0;
}
}
window.onload = function(){
var slide1 = new Slideshow({
images : ["images/image1.jpg","images/image2.jpg","images/image3.jpg"],
speed : 2500,
duration : 3
});
var slide2 = new Slideshow({
images : ["images/image4.jpg","images/image4.jpg","images/imageN.jpg"],
speed : 2500,
duration : 3
});
}
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