Mohammad Istanboli Mohammad Istanboli - 6 months ago 13
jQuery Question

setTimeout Jquery loop work wrong

hello I have a page that have three divs inside of it looks something like thisenter image description here

each div has 500px height what am trying to do is making the screen auto scroll each three seconds till reach the next div position and once its reach the last div go back and start from the beginning and do this for infinite here is my j query code

$(document).ready(function(){
myfunction();
});

num = 0;
function myfunction(){
if(num == 1500)
{
num = 0;
}

setTimeout(function(){$('html, body').animate({scrollTop:num}, "normal")},3000);
num = num + 500;
myfunction();
}

Answer
setTimeout(function(){
  $('html,    body').animate({scrollTop:num}, "normal");  
  num = num + 500;
  myfunction(); 
}
,3000); 
Comments