Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get named function to repeat itself continuously in jQuery

Tags:

jquery

I'm trying to get a function to repeat itself once it starts, but I must be off today because I can't figure it out. Here's my code:

function runNext() {
    galleryNext().delay(1500).runNext();
}

Thanks in advance.

like image 828
CoreyRS Avatar asked Jul 23 '12 17:07

CoreyRS


1 Answers

If you want to call a function on a regular interval you should use setInterval().

var myFunction = function() {};
setInterval(myFunction, 1000); // call every 1000 milliseconds

If you ever need to stop the function from being called forever, setInterval() returns an id that you can use to stop the timer as well. Here's an example.

var myFunction = function() {};
var timer = setInterval(myFunction, 1000);
clearTimeout(timer);
like image 81
jessegavin Avatar answered Sep 24 '22 20:09

jessegavin