javascript - How To Make a Hipmunk Style Progress Bar with Twitter Bootstrap and Jquery -


to surprise, i'm not seeing this.

the bootstrap docs give plenty of options displaying progress bar, no instructions making something.

i'm writing 1 page web app that'll ideally use progress bar transition before switching hidden part of page.

here's simplified html:

html

<div id="part1">     <p>sample app</p>         <button class="analyze btn btn-primary">analyze</button> </div>  <div id="part2">     <!-- html goes here --> </div> 

css

#part2 {    display: none; } 

jquery

$(".analyze").click(function() {     $("#part1").hide();     $("#part2").show(); }); 

this simple. i'd make progress bar dynamically populates on $(".analyze").click , takes fixed amount of time complete before #part2 becomes visible using bootstrap progress bar.

something similar hipmunk, or many of other airline aggregator sites do.

ideally compatible across browsers , uses jquery since i'm using make of ui app.

you can make use of javascript function setinterval repeatedly run function on , on again. easy way change width of on given amount of time.

html

<div id="instance" class="progress">   <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">     <span class="sr-only">0% complete</span>   </div> </div>  <div class="show-on-done hidden">here other stuff</div> 

javascript:

function fakeprogress(container, durationinms, ondone) {     var intervalinms = 200;     var donedelay = intervalinms * 2;     var bar = container.find('.progress-bar');     var sronly = bar.find('.sr-only');     var percent = 0;      var interval = setinterval(function updatebar() {         percent += 100 * (intervalinms/durationinms);         bar.css({width: percent + '%'});         bar['aria-valuenow'] = percent;         sronly.text(percent + '% complete');          if (percent >= 100) {             clearinterval(interval);             settimeout(function() {                 if (typeof ondone === 'function') {                     ondone();                 }             }, donedelay);         }     }, intervalinms); } 

then call javascript:

var duration = 1000;  // in milliseconds function ondone() {     $('.show-on-done').removeclass('hidden'); }  fakeprogress($('#instance'), duration, ondone); 

jsfiddle: https://jsfiddle.net/6ht5umxz/3/


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -