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.
- (function($) {
- $.fn.fadeSlideShow = function(options) {
- return this.each(function() {
- settings = $.extend({
- width: 640,
- height: 480,
- speed: 'slow',
- interval: 3000,
- NextElement: '',
- NextElementText: '',
PrevElement: '',
- PrevElementText: '',
- autoplay: true
- }, options);
- // set style for wrapper element
- $(this).css({
- width: settings.width,
- height: settings.height,
- position: 'relative',
- overflow: 'hidden'
- });
- // set styles for child element
- $('> *', this).css({
- position: 'absolute',
- width: settings.width,
- height: settings.height
- });
- // count number of slides
- var items = $("#" + this.id + " ." + this.id + "_slide");
- var current = null;
- var currNo = items.length - 1;
- autoplay = function() {
- intval = setInterval(function() {
- current = (current != null) ? current : items[(items.length - 1)];
- currNo = $.inArray(current, items) + 1
- currNo = (currNo - 1);
- $(items[currNo]).fadeOut(settings.speed);
- currNo = (currNo - 1);
- if (currNo == -1) { currNo = items.length - 1; }
- $(items[currNo]).fadeIn(settings.speed);
- current = items[currNo];
- }, settings.interval);
- }
- stopAutoplay = function() {
- clearInterval(intval);
- intval = false;
- if (settings.PlayPauseElement) {
- $('#' + settings.PlayPauseElement).html(settings.PlayText);
- }
- }
- jumpTo = function(newIndex, curIndex) {
- $(items[curIndex]).fadeOut(settings.speed);
- $(items[newIndex]).fadeIn(settings.speed);
-
- currNo = newIndex;
- }
- if (settings.NextElement) {
- if (!$('#' + settings.NextElement).css('display')) {
- $(this).after('<a href="#" id="' + settings.NextElement + '">' + settings.NextElementText + '<\/a>');
- }
- $('#' + settings.NextElement).bind('click', function() {
- nextSlide = (currNo <= 0) ? items.length - 1 : currNo - 1;
- stopAutoplay();
- jumpTo(nextSlide, currNo);
- return false;
- });
- }
- if (settings.PrevElement) {
- if (!$('#' + settings.PrevElement).css('display')) {
- $(this).after('<a href="#" id="' + settings.PrevElement + '">' + settings.PrevElementText + '<\/a>');
- }
- $('#' + settings.PrevElement).bind('click', function() {
- prevSlide = (currNo >= items.length - 1) ? 0 : currNo + 1;
- stopAutoplay();
- jumpTo(prevSlide, currNo);
- return false;
- });
- }
- if (settings.autoplay) { autoplay(); } else { intval = false; }
- });
- };
- })(jQuery);