最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Continuous Progress Bar in Javascript - Stack Overflow

programmeradmin2浏览0评论

I am trying to find the best option to create a simple progress bar that I need to be triggered periodically from within another JavaScript script.

Every few minutes, a timer would cause the progress bar to start going from 0 to 100%. Once it reaches 100%, the bar would reset to 0.

I am trying to implement a smooth animated version of the bar, like this one: /. (I tried adapting this particular one but I could not get it to work the way I described)

I am looking into the jQuery UI ProgressBar: Is it possible to use it in the manner I have described?

Thank you.

I am trying to find the best option to create a simple progress bar that I need to be triggered periodically from within another JavaScript script.

Every few minutes, a timer would cause the progress bar to start going from 0 to 100%. Once it reaches 100%, the bar would reset to 0.

I am trying to implement a smooth animated version of the bar, like this one: http://www.webappers./progressBar/. (I tried adapting this particular one but I could not get it to work the way I described)

I am looking into the jQuery UI ProgressBar: Is it possible to use it in the manner I have described?

Thank you.

Share edited Mar 23, 2010 at 3:13 Jon Limjap 95.6k15 gold badges103 silver badges153 bronze badges asked Mar 23, 2010 at 3:09 GoroGoro 10.2k23 gold badges80 silver badges108 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

This is pretty quick to do with the jQuery UI progress bar, just call this initially:

$("#progressbar").progressbar({ value: 0 });

And this in your other script, probably via setInterval():

var percentComplete = 40; //Get the percent
$("#progressbar").progressbar( { value: percentComplete } );

Put it together like this:

var percentComplete = 0; //Update this in your other script
$("#progressbar").data("progress", setInterval(function() {
  if(percentComplete == 100) {
    percentComplete = 0;
    clearInterval($("#progressbar").data("progress")); //Stop updating
  }
  $("#progressbar").progressbar( { value: percentComplete } );
}, 200));

The animated effect keeps it a bit smoother looking as well: see here for a demo. This is done via a single CSS rule, in the demo case:

.ui-progressbar-value { background-image: url(images/pbar-ani.gif); }
发布评论

评论列表(0)

  1. 暂无评论