您必须将当前图像索引存储在全局变量中。
var currentIndex = 0;
var lastIndex = $('.normsize img').size() - 1;
function showPic(index) {
$('.normsize img:visible').hide();
$('.normsize img:eq('+index+')').fadeIn();
currentIndex = index;
}
$('.photos a').click(function() {
showPic($('.photos a').index(this));
});
$('#next').click(function() {
// If is the last go to first, else go to next
showPic(currentIndex == lastIndex ? 0 : currentIndex + 1);
});
$('#prev').click(function() {
// If is the first, go to last, else go to previous
showPic(currentIndex == 0 ? lastIndex : currentIndex - 1);
});
$('.normsize img').hide(); // Hide all
showPic(0); // Initialize first picture shown