Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.widget("ui.slideshow", {
  2.     options: {
  3.         timer: false,
  4.         transform: 'left',
  5.         intervalo: 2000,
  6.         velocidade: 500
  7.     },
  8.     _init: function(){     
  9.         this.start();
  10.     },
  11.     start: function(){
  12.         this.stop();
  13.         var slideshowdiv = this.element;       
  14.         var largura = $(slideshowdiv).find('img:first').width();
  15.         var altura = $(slideshowdiv).find('img:first').height();
  16.         var totalimagens = $(slideshowdiv).find('img').length;
  17.                
  18.         var intervalo = this.options.intervalo;
  19.         var transform = this.options.transform;
  20.         var velocidade = this.options.velocidade;
  21.        
  22.         var wrapper = $('<div id="slideshowwrapper" />').width(largura).height(altura).css({'overflow':'hidden','position':'relative','margin':'0 auto'});
  23.         $(slideshowdiv).wrap(wrapper);
  24.         $(slideshowdiv).children('div').css({'position':'relative','display':'inline-block'});     
  25.        
  26.        
  27.         ReverseImages = function(direction){
  28.             $(slideshowdiv).children('div').each(function(cont){
  29.                 if(cont > 0)
  30.                     $(this).prependTo($(slideshowdiv));
  31.             });
  32.             if (direction == 'horizontal')
  33.                 $(slideshowdiv).css('margin-left', '-' + largura * (totalimagens - 1) + 'px');
  34.             else if (direction == 'vertical')
  35.                 $(slideshowdiv).css('margin-top', '-' + altura * (totalimagens - 1) + 'px');
  36.         };
  37.        
  38.         switch(this.options.transform){
  39.             case 'left':
  40.                 $(slideshowdiv).width(largura * totalimagens).height(altura);
  41.                 this.options.timer = window.setInterval("ChangeImageLeft(" + velocidade + ")", intervalo);
  42.             break;
  43.             case 'right':              
  44.                 $(slideshowdiv).width(largura * totalimagens + 4).height(altura);
  45.                 ReverseImages('horizontal');                   
  46.                 this.options.timer = window.setInterval("ChangeImageRight(" + velocidade + ")", intervalo);
  47.             break;
  48.             case 'up':
  49.                 $(slideshowdiv).height(altura * totalimagens).width(largura);                          
  50.                 this.options.timer = window.setInterval("ChangeImageUp(" + velocidade + ")", intervalo);
  51.             break;
  52.             case 'down':                           
  53.                 $(slideshowdiv).height(altura * totalimagens).width(largura);
  54.                 ReverseImages('vertical');
  55.                 this.options.timer = window.setInterval("ChangeImageDown(" + velocidade + ")", intervalo);
  56.             break;
  57.             case 'fade':
  58.                 $(slideshowdiv).height(altura).width(largura);                         
  59.                 this.options.timer = window.setInterval("ChangeImageFade(" + velocidade + ")", intervalo);
  60.             break;
  61.             case 'seethrough':
  62.                 $(slideshowdiv).children('div').css('position','absolute');
  63.                 $(slideshowdiv).height(altura).width(largura);                         
  64.                 this.options.timer = window.setInterval("ChangeImageSeethrough(" + velocidade + ")", intervalo);
  65.             break;
  66.             case 'png':
  67.                 if(!$.browser.msie){
  68.                     $(slideshowdiv).height(altura).width(largura);
  69.                     $(slideshowdiv).children('div').css({'position':'absolute','opacity':'0'});
  70.                     $(slideshowdiv).children('div:last').css({'opacity':'1'});
  71.                     this.options.timer = window.setInterval("ChangeImagePNG(" + velocidade + ")", intervalo);
  72.                 } else{
  73.                     $(slideshowdiv).height(altura).width(largura);
  74.                     $(slideshowdiv).children('div').css({'position':'absolute'}).hide();
  75.                     $(slideshowdiv).children('div:last').show();
  76.                     this.options.timer = window.setInterval("ChangeImagePNGIE(" + velocidade + ")", intervalo);
  77.                 }
  78.                 break;         
  79.         }
  80.        
  81.         ChangeImageLeft = function(velocidade){
  82.             $(slideshowdiv).animate({'margin-left' : '-=' + largura } , velocidade, function(){
  83.                 $(slideshowdiv).children('div:first').appendTo($(slideshowdiv));
  84.                 $(slideshowdiv).css('margin-left','0');
  85.                 }
  86.             );
  87.         };
  88.         ChangeImageRight = function(){                     
  89.             $(slideshowdiv).animate({'margin-left' : '+=' + largura } , velocidade, function(){
  90.                 $(slideshowdiv).children('div:last').prependTo($(slideshowdiv));
  91.                 $(slideshowdiv).css('margin-left', '-' + largura * (totalimagens - 1) + 'px');
  92.                 }
  93.             );
  94.         };
  95.         ChangeImageUp = function(){                    
  96.             $(slideshowdiv).animate({'margin-top' : '-=' + altura } , velocidade, function(){
  97.                 $(slideshowdiv).children('div:first').appendTo($(slideshowdiv));
  98.                 $(slideshowdiv).css('margin-top', '0');
  99.                 }
  100.             );
  101.         };
  102.         ChangeImageDown = function(){                      
  103.             $(slideshowdiv).animate({'margin-top' : '+=' + altura } , velocidade, function(){
  104.                 $(slideshowdiv).children('div:last').prependTo($(slideshowdiv));
  105.                 $(slideshowdiv).css('margin-top', '-' + altura * (totalimagens - 1) + 'px');
  106.                 }
  107.             );
  108.         };
  109.         ChangeImageFade = function(){
  110.             $(slideshowdiv).children('div:first').fadeOut(velocidade/2, function(){
  111.                 $(slideshowdiv).children('div:first').appendTo($(slideshowdiv));
  112.                 $(slideshowdiv).children('div:first').fadeIn(velocidade/2);
  113.             });
  114.         };
  115.         ChangeImageSeethrough = function(){        
  116.             $(slideshowdiv).children('div:last').animate({'opacity': 0.0}, velocidade, function(){             
  117.                 $(slideshowdiv).children('div:last').css('opacity','1.0');
  118.                 $(slideshowdiv).children('div:last').prependTo($(slideshowdiv));
  119.             });
  120.         };
  121.         ChangeImagePNG = function(){           
  122.             $(slideshowdiv).children('div:last').animate({'opacity': 0.0}, velocidade, function(){             
  123.                 $(slideshowdiv).children('div:last').prependTo($(slideshowdiv));
  124.             }).prev('div').animate({'opacity': 1.0}, velocidade);          
  125.         };
  126.         ChangeImagePNGIE = function(){         
  127.             $(slideshowdiv).children('div:last').hide().prev('div').show();            
  128.             $(slideshowdiv).children('div:last').prependTo($(slideshowdiv));   
  129.         };
  130.     },
  131.     stop: function(){
  132.         this.element.css('margin-left','0').css('margin-top','0');
  133.         if (this.options.timer) {
  134.             clearInterval(this.options.timer);
  135.             this.options.timer = false;
  136.         }
  137.     }    
  138. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement