$(document).ready(function(){ var totwidth=0; var positions = new array(); $('#slides .slide').each(function(i){ positions[i]= totwidth; totwidth += $(this).width(); if(!$(this).width()) { alert("please, fill in width & height for all your images!"); return false; } }); $('#slides').width(totwidth); $('#dots a').mouseover(function(e,keepscroll){ $('a.menuitem').removeclass('act').addclass('inact'); $(this).addclass('act'); var pos = $(this).prevall('.menuitem').length; $('#slides').stop().animate({marginleft:-positions[pos]+'px'},450); e.preventdefault(); if(!keepscroll) clearinterval(itvl); }); $('#dots a.menuitem:first').addclass('act').siblings().addclass('inact'); var current=1; function autoadvance() { if(current==-1) return false; $('#dots a').eq(current%$('#dots a').length).trigger('mouseover',[true]); current++; } var changeevery = 20; var itvl = setinterval(function(){autoadvance()},changeevery*200);//设置自动播放时间,越大越慢 });