我创建了一个UI,其中当服务返回真值时,我创建了一个加载条,加载条将达到100%,达到100%后,用户应重定向到另一个页面。

让我们假设,如果服务返回假值,则状态栏将保持10%的负载。

Link to jsfiddle

我已经创建了函数,编写了进度条逻辑,并在服务返回true并重定向到其他URL时返回true值。

一切都很好。但是我希望进度条达到100%,然后只重定向用户。下面是代码(上面是jsfiddle链接):

var serviceStatus = true; // Suppose value from service
var elem = document.getElementById("blueBar");
var perNum = document.getElementById("progressPercentage");

var width = 10; // intial progress bar width
var id = setInterval(progressBar, 10);
function progressBar() {
    if (width >= 100 || serviceStatus === false) {
        clearInterval(id);
        return false;
    } else {
        width ++;
        elem.style.width = width + '%';
        perNum.innerHTML = width * 1  + '%';
        //return true;
    }
}

function redirectUser(progressBar) {
    console.log(progressBar);
    // if (frame === true) {
    //  window.location = "http://www.google.com";
    // };
}

redirectUser(progressBar());


谢谢,有什么问题吗?请问。

最佳答案

在这里,您https://jsfiddle.net/4t6bppjs/10/

function redirectUser(progressBar) {
    if(progressBar) {
        setTimeout( function() {
            //---- window.location
        }, 1000);
    }
}


我刚刚添加了setTimeout。

关于javascript - 增量值达到100时,将用户重定向到另一页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44966633/

10-09 16:18