Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and Twitter Bootstrap progress bar [closed]

I have this code:

<div class="progress">
    <div class="bar" style="width: 0%;"></div>
</div>

What should I do, so when I click a button somewhere on the website, the width will go from 0 to 100, in a specific time, and give the effect of a loading progress bar?

Thanks.

like image 730
Amar Syla Avatar asked Jun 30 '26 22:06

Amar Syla


2 Answers

jQuery animate, as mentioned already, will do that. Change the duration to fit the time you want

$('.bar').animate({ width: "100%" },2000);
like image 81
Simon C Avatar answered Jul 02 '26 12:07

Simon C


You may try this (using jQuery ui)

$(function() {
    $( "#progressbar" ).progressbar();
    $('#progress').click(function(){
        var progressbar = $( "#progressbar" ),
        progressLabel = $( ".progress-label" );
        progressLabel.show();
        progressbar.progressbar({
            value: false,
            change: function() {
                progressLabel.text( progressbar.progressbar( "value" ) + "%" );
            },
            complete: function() {
                progressLabel.text( "Complete!" );
            }
        });

        function progress() {
            var val = progressbar.progressbar( "value" ) || 0;
            progressbar.progressbar( "value", val + 1 );
            if ( val < 99 ) {
                setTimeout( progress, 50 );
            }
        }
        setTimeout( progress, 10 );
    });
});

DEMO.

like image 27
The Alpha Avatar answered Jul 02 '26 10:07

The Alpha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!