Advertisement
SalahAdDinYusuf

slider.js

Apr 16th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.68 KB | None | 0 0
  1. function wideSlider(){
  2.        
  3.         var status = true; //Esta variable activa la reproducción automática
  4.         var statusload = true;
  5.         var timer; //Este es el intervalo de tiempo para la rotación automática
  6.         var big_positions = new Array(); //Acá guardamos las posiciones de las imágenes grandes
  7.                 var amount = $(".bigimages").children("div").children("a").children("img").length; //Cantidad de imágenes
  8.         var preloaded = 0; //Images preloaded counter
  9.         var root = this;
  10.         $(".bigimages").hide();
  11.         $(".bigimages").children("div").children("a").children("img").load(preloaderImages);
  12.         $(".bigimages").children("div").children("a").children("img").each(images);
  13.         function images(){
  14.             if(this.complete && document.all){
  15.                 preloaded++;
  16.                 if(preloaded >= amount && statusload == true){
  17.                     $(".bigimages").fadeIn("slow");
  18.                     statusload = false;
  19.                     show();
  20.                 }
  21.             }
  22.         }
  23.         function preloaderImages(e){
  24.             preloaded++;
  25.             if(preloaded >= amount && statusload == true){
  26.                 $(".bigimages").fadeIn("slow"); //Una vez cargadas las imágenes aplico un fade y muestro las imágenes grandes
  27.                 statusload = false;
  28.                 show(); //Llamo a la función que ejecuta por primera vez el slider
  29.             }
  30.         }
  31.         function show(){
  32.            
  33.             //Guardo las posiciones de las imágenes grandes
  34.             $(".bigimages").children("div").each(saveBig);
  35.             function saveBig(index,element){
  36.                 var width = $(this).width();
  37.                 var position = width * index;
  38.                 big_positions[index] = position;
  39.                 $(this).css("left", position); //Place big images
  40.             }
  41.             //Llamo a la función que produce la reproducción automática por primera vez!
  42.             autoRotation(0);
  43.             function autoRotation(position){
  44.                 //Marco la siguiente posición como la actual
  45.                 var nextposition = position;
  46.                 //Vuelvo a crear el timer
  47.                 timer = window.setTimeout(function(e){
  48.                     if(nextposition == big_positions.length - 1){ //Si llegue a la última imagen, vuelvo a empezar ;)
  49.                         nextposition = 0;
  50.                     }else{
  51.                         nextposition++;
  52.                     }
  53.                     //Cuando termina la animación, habilito que pueda existir una siguiente (esto es para evitar los problemas de render de los navegadores y que no aparezcan todas las animaciones juntas cuando maximisamos el navegador antes oculto)
  54.                     if(status == true){
  55.                         //Animación para las imágenes grandes
  56.                         $('.bigimages').animate({right: big_positions[nextposition]},speed * 1000,"swing",function(){ status = true; });
  57.                     }
  58.                     status = false;
  59.                     window.clearTimeout(timer);
  60.                     //Genero la recursividad ejecutando nuevamente la función en la que estoy, con esto el loop infinito de animación cíclica
  61.                     autoRotation(nextposition);
  62.                 }, time * 1000);
  63.             }
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement