xxxxxxxxxx
// setInterval is used to run a piece of code everytime
// a certain amount of time which is defined in ms has been elapsed.
// Basic syntax is as follows:
// setInterval(callback, time);
setInterval(() => {
alert("just checking on you :)");
}, 5000); // displays an alert after every 5 seconds
xxxxxxxxxx
setInterval(function(){
console.log("Oooo Yeaaa!");
}, 2000);//run this thang every 2 seconds
xxxxxxxxxx
function func(){
console.log("Ran")
}
setInterval(func,1000)//Runs the "func" function every second
xxxxxxxxxx
setInterval(function(){
console.log("Hello World!");
}, 2000); //run this script every 2 seconds(specified in milliseconds)
xxxxxxxxxx
// Define the function to be executed repeatedly
function myFunction() {
console.log('Hello, World!');
}
// Set the interval to execute the function every 2 seconds (2000 milliseconds)
setInterval(myFunction, 2000);
xxxxxxxxxx
loadingProgress(max, jump, speed) {
const loadBar = setInterval(() => {
if(this.load_current < max){
this.load_current += jump || 1;
} else {
clearInterval(loadBar);
this.onOk()
if(this.isFrom == 'isReject') {
this.$emit('loadRejectErros');
}
}
}, speed);
},
xxxxxxxxxx
// variable to store our intervalID
let nIntervId;
function changeColor() {
// check if already an interval has been set up
if (!nIntervId) {
nIntervId = setInterval(flashText, 5);
}
}
function flashText() {
const oElem = document.getElementById("my_box");
if (oElem.className === "go") {
oElem.className = "stop";
} else {
oElem.className = "go";
}
}
function stopTextColor() {
clearInterval(nIntervId);
// release our intervalID from the variable
nIntervId = null;
}
document.getElementById("start").addEventListener("click", changeColor);
document.getElementById("stop").addEventListener("click", stopTextColor);
xxxxxxxxxx
The setInterval() method calls a function at specified intervals (in milliseconds).