$(document).ready(function(){ var text_pos=0; var text_p_total=2; var text_p_width=442; $('.text_slider_image').clone().appendTo('.text_slider_panel'); function text_moveSlider(index){ var targetLeft=-(index*text_p_width); var temp=index; if(index>(text_p_total-1)){ index=index-text_p_total; } $('.text_slider_panel').stop(true).animate({left:targetLeft},'slow','swing',function(){ if(temp>(text_p_total-1)){ $('.text_slider_panel').css('left',0); text_pos=temp-text_p_total; } }); } var text_auto_rolling=function(){ rolling=setInterval(function(){ text_pos+=1; text_moveSlider(text_pos); },2000); } var stop_rolling=function(){ clearInterval(rolling); } text_moveSlider(text_pos); text_auto_rolling(); });