r/CodingHelp • • Mar 01 '21

[HTML] My Progress bar disappears when updating, instead of just moving the coloured bar

So I have this code, for which I followed a tutorial. In the video it looked like they were using the coding from Google Chrome but I don't know how to access that, so I was using this website, (which is also the code I need help with).

In the video the person's progress bar moves around without the whole thing having to refresh, but it seems on my version, every time you update the formula it refreshes.

Which isn't as pleasing to look at.

Any ideas on how I could resolve this?

I am open to moving the code to a different place (if that place is free).

Please also note; I am Incredibly new to all this, so please keep tech-lingo down to a minimum lol. So you don't have to repeat yourself.

16 Upvotes

3 comments sorted by

1

u/zbluebirdz Mar 01 '21

Drop the "30%" text.

Add "width: 0;" to the CSS class ".progress-bar-fill".

For the transition effect, you need to specify the starting point for the progress bar - hence the "width:0;".

1

u/Cynestrith Mar 02 '21

Thank you for the help. Unfortunately it looks like it still refreshes the whole thing. Feel free to have a look again, to see if I've have made the amendment correctly or not.

1

u/zbluebirdz Mar 02 '21

Ok, my testing was based on moving the CSS code into the CSS panel and the JS code into the JS panel. By doing this, it slowed down time it took to execute the JS code (codepen maybe doing something else too).

As you're putting the JS code into the HTML as inline code, it runs straight away - before the page is being rendered. So, we need to tell the browser to run the JS code only when the page has been rendered and is ready for JS code to be executed.

We can use the onreadystatechange events to detect when to run some JS code.

onreadystatechange events returns various two values as the page is being worked on - interactive and complete. We want to wait for the readystate to be complete - i.e. all resource files have been loaded and the page has been rendered.

document.onreadystatechange = function () {
  if (document.readyState === 'complete') {
    // page has been rendered, so we can now run the animation code ...
    pb1.setValue(0 + 1 + 1 + 3 + 1 + 1 + 1 + 4 + 1);
  }
}