// 图片幻灯片 function picscroll(id,icon,leftbtn,rightbtn){ var sWidth = $(id).width(); var len = $(id).find("ul li").length; var index = 0; var picTimer; var btn=""; for(var i=0; i < len; i++) { var num = i+1; btn += ""+num+""; } $(icon).html(btn); $(icon).find("span").mouseover(function() { index = $(icon).find("span").index(this); showPics(index); }).eq(0).trigger("mouseover"); $(leftbtn).click(function() { index -= 1; if(index == -1) {index = len - 1;} showPics(index); }); $(rightbtn).click(function() { index += 1; if(index == len) {index = 0;} showPics(index); }); $(id).find("ul").css("width",sWidth * (len)); $(id).hover(function() { clearInterval(picTimer); },function() { picTimer = setInterval(function() { showPics(index); index++; if(index == len) {index = 0;} },5000); }).trigger("mouseleave"); function showPics(index) { var nowLeft = -index*sWidth; $(id).find("ul").stop(true,false).animate({"left":nowLeft},300); $(icon).find("span").stop(true,false).removeClass("on").eq(index).stop(true,false).addClass("on"); } }