Nivo-Gallery
Nivo-Gallery copied to clipboard
goTo() method cannot move to first slide
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.
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');
}
thanks estmatic
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');
}
Thanks Rodrigo....