jQuery(function(){ if((jQuery(".banner img:eq(0)").width()-jQuery(window).width())>0) { jQuery(".banner li").each(function(){ jQuery(this).css("margin-left","-"+(jQuery(".banner img:eq(0)").width()-jQuery(window).width())/2+"px") }); } var nowindex = 0; var speed = "slow"; var time = 6000; var bottoncurrentclass = "current"; var imagesivclass = "banner"; var bottondivclass = "botton"; function autoPlayFn() { var nextindex = nowindex + 1; if (nextindex > jQuery("." + imagesivclass + " li").length - 1) nextindex = 0; jQuery("." + imagesivclass + " li").eq(nowindex).fadeOut(speed, function() { jQuery("." + bottoncurrentclass).removeClass(bottoncurrentclass); jQuery("." + imagesivclass + " li").eq(nextindex).fadeIn(speed); jQuery("." + bottondivclass + " span").eq(nextindex).addClass(bottoncurrentclass); }); nowindex = nextindex; } jQuery(function() { jQuery("." + imagesivclass + " li").hide(); jQuery("." + imagesivclass + " li").eq(nowindex).show(); jQuery("." + bottondivclass + " span").click(function() { var index = jQuery("." + bottondivclass + " span").index(jQuery(this)); var cindex = jQuery("." + bottondivclass + " span").index(jQuery("." + bottoncurrentclass)); jQuery("." + imagesivclass + " li").eq(cindex).fadeOut(speed, function() { jQuery("." + bottoncurrentclass).removeClass(bottoncurrentclass); jQuery("." + imagesivclass + " li").eq(index).fadeIn(speed); jQuery("." + bottondivclass + " span").eq(index).addClass(bottoncurrentclass); }); clearInterval(autoplay); nowindex = index; autoplay = setInterval(autoPlayFn, time); }); var autoplay = setInterval(autoPlayFn, time); }); })