Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JS does not have a sleep function, it has <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout" rel="noreferrer"><strong>setTimeout()</strong></a> or <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setInterval" rel="noreferrer"><strong>setInterval()</strong></a> functions. </p> <p>If you can move the code that you need to run after the pause into the <code>setTimeout()</code> callback, you can do something like this:</p> <pre><code>//code before the pause setTimeout(function(){ //do what you need here }, 2000); </code></pre> <p>see example here : <a href="http://jsfiddle.net/9LZQp/" rel="noreferrer">http://jsfiddle.net/9LZQp/</a></p> <p>This won't halt the execution of your script, but as long as <code>setTimeout()</code> is an asynchronous function, this code</p> <pre><code>console.log("HELLO"); setTimeout(function(){ console.log("THIS IS"); }, 2000); console.log("DOG"); </code></pre> <p>will print this in the console:</p> <pre><code>HELLO DOG THIS IS </code></pre> <p>(note that <strong>DOG</strong> is printed before <strong>THIS IS</strong>)</p> <hr> <p>You can use the following code to simulate a sleep for short periods of time:</p> <pre><code>function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i &lt; 1e7; i++) { if ((new Date().getTime() - start) &gt; milliseconds){ break; } } } </code></pre> <p>now, if you want to sleep for 1 second, just use:</p> <pre><code>sleep(1000); </code></pre> <p>example: <a href="http://jsfiddle.net/HrJku/1/" rel="noreferrer">http://jsfiddle.net/HrJku/1/</a></p> <p>please note that <strong>this code will keep your script busy for <em>n milliseconds</em>. This will not only stop execution of Javascript on your page, but depending on the browser implementation, may possibly make the page completely unresponsive, and possibly make the entire browser unresponsive</strong>. In other words this is almost always the wrong thing to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload