$(function(){ var cT = 3000, sT = 5000; var index = 0, $img = $('#slide').find('div.img_slide'), imgLen = $img.length; $('#slide').css('background','none'); $img.not(':first').css({'opacity':'0','z-index':'0'}); for (var i=0; i< imgLen; i++) { $('#thum ul').append('
  • '); } var $tN = $('#thum li'); $tN.first().addClass('active'); $tN.click(function(){ $img.stop(); clearInterval(slides); $(this).addClass('active').siblings().removeClass('active'); var number = $(this).index(), $choiceImg = $img.eq(number); index = (number) % imgLen; $choiceImg.siblings().animate({'opacity':'0','z-index':'0'},cT); $choiceImg.animate({'opacity':'1','z-index':'19'},cT); start(); }); function start(){ slides = setInterval(function(){ var next = (index +1) % imgLen; $tN.removeClass('active').eq(next).addClass('active'); $img.eq(index).animate({'opacity':'0','z-index':'0'},cT); $img.eq(next).animate({'opacity':'1','z-index':'19'},cT); index = next; },sT + cT); }; start(); });