Window clearInterval() Method - Using setInterval() and clearInterval() to create a dynamic progress bar: - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window clearInterval

Description

Window clearInterval() Method - Using setInterval() and clearInterval() to create a dynamic progress bar:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<style>
#myProgress {//from   w ww.j a va2s  . c o m
  width: 100%;
  height: 30px;
  position: relative;
  background-color: #ddd;
}

#myBar {
  background-color: #4CAF50;
  width: 10px;
  height: 30px;
  position: absolute;
}
</style>
<body>

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

<br>
<button onclick="move()">Click Me</button>

<script>
function move() {
  var elem = document.getElementById("myBar");
  var width = 0;
  var id = setInterval(frame, 10);
  function frame() {
    if (width == 100) {
      clearInterval(id);
    } else {
      width++;
      elem.style.width = width + '%';
    }
  }
}
</script>

</body>
</html>

Related Tutorials