jQueryUI Progress Bar

2019-09-07 22:18发布

问题:

I have never used the jQuery UI progress bar, but I'd like to make a function that would basically load the jQuery UI progress bar, run it for 5 seconds and then execute another function.

ie.

function test() {

show the jQuery UI progress bar for 5 seconds in div ("progressbar")

after 5 seconds has passed..... execute test2()

}

How can this be done?

回答1:

You can do it like this:

​<button onclick="test()">Test</button>
<div id="progress"></div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

With animation:

function test(){
    var per = 0;
    progress(per);
    time = setTimeout(function(){ animate(per); }, 1000);
    setTimeout(function(){ $( "#progress" ).hide(); test2(); }, 5000);

}

function animate(per){

    clearTimeout(time);
    per = per+20;
    progress(per);

    time = setTimeout(function(){ animate(per); }, 1000);
}

function test2(){
    alert('test2');
}
function progress(per){
    $( "#progress" ).progressbar({
        value: per
    });        
}

JSFiddle Example