以前不工作

时间:2012-03-29 18:45:32

标签: jquery slideshow

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();
    });
});

我的“上一页”按钮有问题。在我到达第一张图片后,它停止工作,我的意思是他没有滑到最后一张图片。我真的不知道问题是什么,请帮忙。 (下一步按钮工作正常)

1 个答案:

答案 0 :(得分:0)

如果从第一张图片返回一张画面,则必须将新索引设置为最后一张图像而不是第一张图像,在您的功能中,您始终将图像设置为0

function showPrev(){
    var len = $('#backimg img').length;
    var next = currentIndex > 0 ? currentIndex - 1 : len-1 ;
    showImage(next);
}