+ 6
how to delay in javascript
4 Antworten
+ 3
As Satnam suggested you can use the setTimeout() function, which syntax is:
setTimeout(function, delay);
"function" is the function that you want to be executed after an amount of time equal to the variable "delay" (expressed in milliseconds).
Here is an example:
You want to print something to the console and after 3 seconds (3000 milliseconds), you want to print something else.
You can do something like this:
setTimeout(function(){
console.log("this will appear after")
}, 5000);
console.log("this will appear before");
The output will be:
"this will appear before"
//and after 3 seconds
"this will appear after"
+ 4
Can you give easy example
+ 1
Use the setTimeout() function
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Timeouts_and_intervals#setTimeout()
+ 1
<h1>You can use the function settimeout() to do it 1 time and setInterval() to do it continuously</h1>