How to make a non-blocking sleep in javascript/jqu

2019-04-20 11:25发布

问题:

How to make a non-blocking sleep in javascript/jquery?

回答1:

At the risk of stealing the answer from your commentors, use setTimeout(). For example:

var aWhile = 5000; // 5 seconds
var doSomethingAfterAWhile = function() {
  // do something
}
setTimeout( doSomethingAfterAWhile, aWhile );