$(document).ready(function(){ var pos=0; var p_total=2; var p_width=496; $('.text_slider_image').clone().appendTo('.text_slider_panel'); function moveSlider(index){ var targetLeft=-(index*p_width); var temp=index; if(index>(p_total-1)){ index=index-p_total; } $('.text_slider_panel').stop(true).animate({left:targetLeft},'slow','swing',function(){ if(temp>(p_total-1)){ $('.text_slider_panel').css('left',0); pos=temp-p_total; } }); } var auto_rolling=function(){ rolling=setInterval(function(){ pos+=1; moveSlider(pos); },2000); } var stop_rolling=function(){ clearInterval(rolling); } moveSlider(pos); auto_rolling(); });