3 Replies - 580 Views - Last Post: 06 October 2016 - 10:56 AM

#1 makamo66   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 110
  • Joined: 04-February 09

Zero Progress Bar

Posted 05 October 2016 - 11:32 AM

I want to set the data-max of my progress bar to zero but doing this causes the progress bar to count 'til infinity (100 divided by zero). How can I set my progress bar to zero?

Here is my HTML:

<progress class="progressbar" value="0" max="100" data-max="1"></progress>


I link to jquery and modernizr.

Here is my javascript:

    $(document).ready(function() {

      $('.progressbar').each(function() {
        var progressbar = $(this),
          progressbarValue = progressbar.next(),
          value = progressbar.data('min') || 0,
          max = progressbar.data('max'),
		 time = (100 / max) * 5,
          value = progressbar.val(),
          animate = setInterval(loading, time);

        function loading() {
          value += 1;
          progressbar.val(value);
          progressbarValue.html(value + '%');
          if (value == max) {
            clearInterval(animate);
          }
        };
      })
    });


Is This A Good Question/Topic? 0
  • +

Replies To: Zero Progress Bar

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3134
  • View blog
  • Posts: 8,931
  • Joined: 15-January 14

Re: Zero Progress Bar

Posted 05 October 2016 - 02:02 PM

If by "set the progress bar to 0" you mean don't show any progress, you just set the value to 0.

progressbar.val(0);

Was This Post Helpful? 0
  • +
  • -

#3 makamo66   User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 110
  • Joined: 04-February 09

Re: Zero Progress Bar

Posted 06 October 2016 - 03:58 AM

That does work but the problem is that I have several progress bars and I don't want to set all of them to zero. If I change the javascript then all of the progress bars have to be zero.
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3134
  • View blog
  • Posts: 8,931
  • Joined: 15-January 14

Re: Zero Progress Bar

Posted 06 October 2016 - 10:56 AM

OK, well, I'm not sure what your goal is here but hopefully you can figure it out. Maybe use another data attribute to differentiate when to set something to zero and when not to, and add conditionals in your code to check for that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1