0
var currentImage;
var currentIndex = 0;
function showImage(index){
    if(index < $('#backimg img').length){
        var indexImage = $('#backimg img')[index]
        if(currentImage){   
            if(currentImage != indexImage ){
                $(currentImage).css('z-index',2);
                $(currentImage).fadeOut(250, function() {
                    $(this).css({'display':'none','z-index':1})
                });
            }
        }
        $(indexImage).css({'display':'block', 'opacity':1});
        currentImage = indexImage;
        currentIndex = index;
        $('#thumbs li').removeClass('active');
        $($('#thumbs li')[index]).addClass('active');
    }
}
function showNext(){
    var len = $('#backimg img').length;
    var next = currentIndex < (len-1) ? currentIndex + 1 : 0;
    showImage(next);
} 
function showPrev(){
    var len = $('#backimg img').length;
    var next = currentIndex > 0 ? currentIndex - 1 : 0;
    showImage(next);
} 
$(document).ready(function() {
    showNext();
    showPrev();
    $('#thumbs li').bind('click',function(e){
        var count = $(this).attr('rel');
        showImage(parseInt(count)-1);
    });
    $('#prev a').click(function () { 
        showPrev();
    });
    $('#next a').click(function () { 
        showNext();
    });
});

I have a problem with the "previous" button. After I reach the first image, it stops working, I mean he doesn't slide to the last one. I really don't know what the problem is, please help. (Next button is working perfect)

Schito
  • 27
  • 4

1 Answers1

0

you have to set your new index to the last image not to the first if you go back one stap from the first image, in your function u always set the image to 0

function showPrev(){
    var len = $('#backimg img').length;
    var next = currentIndex > 0 ? currentIndex - 1 : len-1 ;
    showImage(next);
}
  • it's working! But it's possible to insert a preloader for images? – Schito Mar 29 '12 at 18:56
  • of course but thats a diffrent topic, there are lots of possible implementations for preloaders - see : http://stackoverflow.com/questions/476679/preloading-images-with-jquery – blackBox solutions Mar 29 '12 at 19:00