Javascript 脚本在进度条启动之前执行
我有一个问题,我的进度条在其余代码完成后启动。现在我知道怎么了,但我找不到下一步的方法 我意识到发生的事情是异步的,我需要使用承诺。你能看看我的代码并给出一些提示吗Javascript 脚本在进度条启动之前执行,javascript,jquery,progress-bar,Javascript,Jquery,Progress Bar,我有一个问题,我的进度条在其余代码完成后启动。现在我知道怎么了,但我找不到下一步的方法 我意识到发生的事情是异步的,我需要使用承诺。你能看看我的代码并给出一些提示吗 var count=1; var SIZE =100 function test() { if (count < SIZE) { var value = Math.round((count / SIZE) * 100); count++;
var count=1;
var SIZE =100
function test() {
if (count < SIZE) {
var value = Math.round((count / SIZE) * 100);
count++;
setTimeout(function () {
$('.progress-bar').css('width', value + '%').attr('aria-valuenow', value);
test();
}, 100);
}
return;
};
test().then($('body').css('background-color', '#76870b'));
我希望运行测试,然后执行其他代码 在这种情况下,可以在第一个函数末尾调用第二个函数 var计数=1; 变量大小=100 功能测试{ 如果计数<大小{ var值=Math.roundcount/大小*100; setTimeoutfunction{ $'.progress bar'.css'width',value+'%'.attr'aria-valuenow',value; }, 100; } console.log'Im Executed'; secondFunction;//调用第二个函数 回来 }; 函数二次函数{ $'body'.css'background-color','76870b' } 测验 var计数=1; 变量大小=100 var测试==>新承诺者解决方案,拒绝=>{ 如果计数<大小{ var值=Math.roundcount/大小*100; setTimeoutfunction{ console.log'sdfsdfsdf'; $'.progress bar'.css'width',value+'%'.attr'aria-valuenow',value; 决心{ “heloo”:“dsfsdf” }; }, 100; }否则{ 拒绝“fdsfsd”; } }; test.thenresp=>{ console.log'hello',resp; $'body'.css'background-color','76870b' }
你想让测试函数成为promise?我更新了原始代码-我忘了在count++中添加计数器。这不起作用。x先生是从Ultravox?的歌曲中取的名字。进度条停止工作。@ChipAhoy它应该起作用,让我再检查一次。不,事实上它是从《生化危机》游戏中取来的,但我使用了due Mr UnknownI在原始代码中添加了缺失的count+。这就是我期望看到的Zabusa。我想让测试函数运行——这是进度条循环。完成后,再执行其他代码。