setTimeout(thisFunc, 500);
setTimeout(thatFunc, 500);
setTimeout(otherFunc, 500);
finalFunc();
Run Code Online (Sandbox Code Playgroud)
我期望的是thisFunc(),然后是半秒暂停,然后是thatFunc(),然后是半秒暂停,然后是otherFunc(),然后是暂停.然后是finalFunc().
实际发生的是,页面暂停1 1/2秒,然后所有四个函数似乎立即执行.
我怎样才能实现我的暂停?它完全是为了UI中的美学目的而完成的.
如果需要使用500 ms作为变量,也可以使用回调:
var timeout = 500;
setTimeout(function() {
thisFunc();
setTimeout(function() {
thatFunc();
setTimeout(function() {
otherFunc();
}, timeout);
}, timeout);
}, timeout);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |