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)
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