Home javascript How to delay JavaScript?

How to delay JavaScript?

Author

Date

Category

How to delay without starting a function? ie. Is it possible to approximately so setTimeout (, 100) for example. Or as in Pascalie delay ();


Answer 1, Authority 100%

“Delays” is that girls can happen, with JS in this case everything is somewhat different.
You can pause the JavaScript code using the Alert, Confirm, Prompt function (still “debugger”, but this is a completely different story).
In all other cases, use “SetTimeout” and Callbacks.

What is the priority to your visibility area:

var i = 'hi, there!';
SetTimeout (Function () {Document.getelementByid ("Mark"). Innerhtml = i;}, 2000);

But such stop writing:

Need to pass. I will help) I start)))

here or help, or will not help, tired of reading from the question of this phrase.


Answer 2

as option:

Function Sleep (Millis) {
  var t = (new date ()). GetTime ();
  var i = 0;
  While (((New Date ()). GetTime () - T) & lt; Millis) {
    I ++;
  }
}

and call:

Sleep (2000); // Time in milliseconds

Answer 3

const delay = async (ms) = & gt; AWAIT NEW PROMISE (RESOLVE = & GT; SETTIMEOUT (RESOLVE, MS));

Usage:

const actionswithdelay = delay (1000) .then (() = & gt; Some Actions);

or

const actionwithdelay = async () = & gt; {
  Await Delay (2000);
  Some Actions;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions