Use the setInterval
function.
This will keep calling the function after an amount of time.
Example:
var myFunction = function () {
//do something
};
setInterval(myFunction, 1000)
In this example it will call myFunction
every 1000 mini seconds.
KEY:
1000 ms = 1 s
You can also cancel a setInterval
with the script:
//create an variable for the setInterval
var intervalId = setInterval(myFunction, 2500);
//That is 2.5 seconds
//Now to cancel the interval:
clearInterval(intervalId);
Use the clearInterval();
to stop an interval.
in the ()
put the interval name you want to stop.
CALLING MULTIPLE FUNCTIONS OR DO SOMETHING:
To call multiple functions at a time or do something else, use this:
var intervalId = setInterval(function () {
//put whatever you want here, I'll put some examples
callAFunction();
inputFunction("123Example...");
alert("Hello!");
//Not a function, just as I said, you can do whatever you want here
console.log("setInterval Is great"); //Not a function!!!!!!!!!!!!!
//This is a comment
/*
This is
another
*/
functionCall();
//here is the end of this variable
}, 100); //the number is the amount of ms after it loops again
You see? This is very useful!
Tell me if I said something you don't want to do.
^_^