Nivo-Gallery icon indicating copy to clipboard operation
Nivo-Gallery copied to clipboard

goTo() method cannot move to first slide

Open estmatic opened this issue 13 years ago • 4 comments

The goTo() method works fine unless you try to go to the first slide. The index is supposed to be zero-based, but the method decrements it, finds that it's less than zero, and sets it to the index of the last slide. Any index > 0 seems to work fine.

estmatic avatar Nov 30 '11 19:11 estmatic

I modified the method and it seems to be working well. Just thought I'd share:

plugin.goTo = function(idx){
  if(idx == global.currentSlide || global.animating) return;

  $(global.slides[global.currentSlide]).fadeOut(plugin.settings.animSpeed);
  if(idx == 0){
    global.currentSlide = (global.totalSlides - 1);
  } else {
    global.currentSlide = (idx - 1);
    if(global.currentSlide < 0) global.currentSlide = global.totalSlides - 1;
    if(global.currentSlide >= global.totalSlides - 1) global.currentSlide = global.totalSlides - 2;
  }

  plugin.pause();
  runTransition('next');
}

estmatic avatar Dec 01 '11 20:12 estmatic

thanks estmatic

nefilas avatar Sep 25 '12 12:09 nefilas

In reality, the estmatic solution, although it works, it's logically incorrect. The correct and simpler solution is to only add an "else" before the last "if" of the goTo function like this:

/*just copy and paste the function below in place of the old one*/
plugin.goTo = function(idx) {
    if(idx == global.currentSlide || global.animating) return;
    $(global.slides[global.currentSlide]).fadeOut(plugin.settings.animSpeed);
    global.currentSlide = (idx - 1);
    if(global.currentSlide < 0) global.currentSlide = global.totalSlides - 1;
    //the if below didn't had an else before it. it's the only thing that was missing for it to work.
    else if(global.currentSlide >= global.totalSlides - 1) global.currentSlide = global.totalSlides - 2;
    plugin.pause();
    runTransition('next');
}

RodrigoFurtado avatar May 07 '13 19:05 RodrigoFurtado

Thanks Rodrigo....

reznextsolutions avatar May 24 '13 04:05 reznextsolutions