var len = $("#b span").length, curindex = 0;$("#leftRun").click(function(){ if(curindex) { curindex--; }else{ return; } $("#b").animate({ left: "-" + curindex * 105 }, 300); $(".ser_nav>span").eq(curindex).mouseover(); });$("#rightRun").click(function(){ if(curindex == len - 5) { return; }else{ curindex++; } $("#b").animate({ left: "-" + curindex * 105 },300); $(".ser_nav>span").eq(curindex).mouseover();});