$(function(){ var cT = 500, sT = 3000; var index = 0, $img = $('#slide').children('div'), imgLen = $img.length; $img.not(':first').css('display','none'); for (var i=0; islide'); } 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().stop().fadeOut( 'cT', function(){ $(this).animate({'opacity': 0}); } ); $choiceImg.css({'opacity': 1}).stop().fadeIn(); start(); }); var $btn_next = $('#btn_next'), $btn_prev = $('#btn_prev'); $btn_next.click(function(){ var next = (index +1) % imgLen; $tN.eq(next).click(); }); $btn_prev.click(function(){ var prev = (index -1) % imgLen; $tN.eq(prev).click(); }); function start(){ slides = setInterval(function(){ var next = (index +1) % imgLen; $tN.removeClass('active').eq(next).addClass('active'); $img.eq(index).stop().fadeOut( 'cT', function(){ $(this).animate({'opacity': 0}); } ); $img.eq(next).stop().css({'opacity': 1}).stop().fadeIn(); index = next; },sT + cT); }; start(); var $tab = $('#tab'), $li = $tab.find('li'), $select = $tab.find('select'); $li.click(function(){ var target = $(this).attr('data-target'); if($(target).is(':hidden')) { $(target).fadeIn(300).siblings().hide(); $(this).addClass('active').siblings().removeClass('active'); $select.val(target); } }); $select .prop('selectIndex',1) .change(function(){ var i = $(this).prop('selectedIndex'); $li.eq(i).trigger('click'); }); });