Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
JavaScript Progress Bar in Loop

I would like to show a progress bar while running the following code. I'm calling it a script. I need a progress bar in a for loop in javascript.

<div id="myProgress">
  <div id="myBar"></div>
</div>

<script>
var i = 0;
var elem = document.getElementById("myBar");
    var width = 1;
    var id = setInterval(frame, 500);
    function frame() {
      if (width >= 100) {
        clearInterval(id);
        i = 0;
      } else {
        width++;
        elem.style.width = width + "%";
      }
    }
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want progress bar infinite execute, see this below code

var i = 0
var elem = document.getElementById("myBar")
let width = 1
var id = setInterval(frame, 50)

function frame() {
  if (width >= 100) {
    clearInterval(id)
    i = 0
    width = 0
    setInterval(frame, 50)
  } else {
    width++
    elem.style.width = width + "%"
  }
}
body {
  font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

#myProgress {
  border: 1px solid black;
  width: 20rem;
}

#myBar {
  border: 1px solid black;
  background-color: black;
}
    <div id="myProgress">
      <div id="myBar"></div>
    </div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!