function func(){
console.log("Ran")
}
setInterval(func,1000)//Runs the "func" function every second
setInterval(function(){
console.log("Hello World!");
}, 2000); //run this script every 2 seconds(specified in milliseconds)
setInterval(function() {
//Your code
}, 1000); //Every 1000ms = 1sec
this.interval = setInterval(() => {
this.currentTime = this.currentTime + 10;
console.log(this.currentTime);
}, 1000);
setInterval(function(){
console.log("Hello");
console.log("World");
}, 2000); //repeat every 2s
// 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
setInterval(function, milliseconds);
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);
},
The setInterval() method calls a function at specified intervals (in milliseconds).
// 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);
pauseTimeLine(value) {
clearInterval(this.interval);
}
<script type="text/javascript">
function getFeed() {
$.ajax({
url: 'get_news_feed.php',
type: 'POST',
success: function(data) {
$('#result').html(data);
}
});
}
$(document).ready(function() {
setInterval(getFeed, 5000);
});
</script>