FadeSlideShow Multiple instances.

FadeSlideShow Multiple instances.

Hi All,

I am in the process of modifying the fadeslideshow by Pascal Bajorat as I found that it was not capable of supporting multiple slideshows on the page.

I am to the point where the i can have multiple slideshows on the page but the Next and prev buttons only effect the last slideshow that is being rendered.  My initial thoughts is the array of slideshow items that i create to control the count and fade in/ out effects for the slides is not being associated seperately with each slideshow but being overwritten by each successive slideshow.  The reason i am thinking this is that the passed parameters are also being overwritten by the later implemented slideshows.

If anyone can let me know what i have done wrong or point me in the direction with some samples that would be awesome. Im still pretty new to jquery so def still in the deep end.  Also if there are better ways to do anything please let me know. Code attached below.

Thanks in advance.

  1. (function($) {
  2.     $.fn.fadeSlideShow = function(options) {
  3.         return this.each(function() {
  4.             settings = $.extend({
  5.                 width: 640, 
  6.                 height: 480,
  7.                 speed: 'slow', 
  8.                 interval: 3000,
  9.                 NextElement: '',
  10.                 NextElementText: '',
                    PrevElement: '',

  11.                 PrevElementText: '',
  12.                 autoplay: true
  13.             }, options);

  14.             // set style for wrapper element
  15.             $(this).css({
  16.                 width: settings.width,
  17.                 height: settings.height,
  18.                 position: 'relative',
  19.                 overflow: 'hidden'
  20.             });

  21.             // set styles for child element
  22.             $('> *', this).css({
  23.                 position: 'absolute',
  24.                 width: settings.width,
  25.                 height: settings.height
  26.             });

  27.             // count number of slides
  28.             var items = $("#" + this.id + " ." + this.id + "_slide");
  29.             var current = null;
  30.             var currNo = items.length - 1;

  31.             autoplay = function() {
  32.                 intval = setInterval(function() {
  33.                     current = (current != null) ? current : items[(items.length - 1)];
  34.                     currNo = $.inArray(current, items) + 1

  35.                     currNo = (currNo - 1);
  36.                     $(items[currNo]).fadeOut(settings.speed);

  37.                     currNo = (currNo - 1);
  38.                     if (currNo == -1) { currNo = items.length - 1; }
  39.                     $(items[currNo]).fadeIn(settings.speed);

  40.                     current = items[currNo];

  41.                 }, settings.interval);
  42.             }

  43.             stopAutoplay = function() {
  44.                 clearInterval(intval);
  45.                 intval = false;
  46.                 if (settings.PlayPauseElement) {
  47.                     $('#' + settings.PlayPauseElement).html(settings.PlayText);
  48.                 }
  49.             }

  50.             jumpTo = function(newIndex, curIndex) {
  51.                 $(items[curIndex]).fadeOut(settings.speed);
  52.                 $(items[newIndex]).fadeIn(settings.speed);
  53.                
  54.                 currNo = newIndex;
  55.             }

  56.             if (settings.NextElement) {
  57.                 if (!$('#' + settings.NextElement).css('display')) {
  58.                     $(this).after('<a href="#" id="' + settings.NextElement + '">' + settings.NextElementText + '<\/a>');
  59.                 }

  60.                 $('#' + settings.NextElement).bind('click', function() {
  61.                     nextSlide = (currNo <= 0) ? items.length - 1 : currNo - 1;
  62.                     stopAutoplay();
  63.                     jumpTo(nextSlide, currNo);
  64.                     return false;
  65.                 });
  66.             }

  67.             if (settings.PrevElement) {
  68.                 if (!$('#' + settings.PrevElement).css('display')) {
  69.                     $(this).after('<a href="#" id="' + settings.PrevElement + '">' + settings.PrevElementText + '<\/a>');
  70.                 }

  71.                 $('#' + settings.PrevElement).bind('click', function() {
  72.                     prevSlide = (currNo >= items.length - 1) ? 0 : currNo + 1;
  73.                     stopAutoplay();
  74.                     jumpTo(prevSlide, currNo);
  75.                     return false;
  76.                 });
  77.             }

  78.             if (settings.autoplay) { autoplay(); } else { intval = false; }
  79.         });
  80.     };
  81. })(jQuery);