Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/03/2014, 01:47
Avatar de Linton
Linton
 
Fecha de Ingreso: diciembre-2011
Ubicación: Viena
Mensajes: 1.213
Antigüedad: 12 años, 4 meses
Puntos: 55
¿Qué le falta a este script de slide con jQuery?

Es para un carrusel de imágenes, las fotos se van turnando y cuando llega la última se repite la serie como un bucle infinito. Dudas:

1.- ¿Hay que poner algo antes en el script, o empieza ahí, sin $(document).ready(function()?

2.- ¿Cómo va el html, basta poner al div una class="rotating-item" o hay que meter id a cada imagen?

3.- ¿numberOfItem es una función interna de jQuery, o hay que cambiarlo por un entero?

Aquí está el código:

Código Javascript:
Ver original
  1. // interval between items
  2.            var itemInterval = 5500;
  3.            var infiniteLoop;//this contains the id of the interval to be used in clearinterval by the way
  4.            setTimeout(function(){
  5.                  // this code will run only once, one second after the page loads.
  6.                  myFunc();
  7.                  infiniteLoop = setInterval(myFunc, itemInterval);
  8.                  // commence loop that will run forever unless you use clearinterval(infiniteLoop);
  9.            }, 1000);
  10.            // start loop
  11.      
  12.            function myFunc() {
  13.                // this code will run every time the function is called
  14.                // initial fade out
  15.                $('.rotating-item').eq(currentItem).fadeOut(fadeTime);
  16.      
  17.                // set counter
  18.                if (currentItem == numberOfItem -1) {
  19.                    currentItem = 0;
  20.                } else {
  21.                    currentItem++;
  22.                }
  23.      
  24.                // next item fade in
  25.                $('.rotating-item').eq(currentItem).fadeIn(fadeTime);
  26.      
  27.            }