How can I make this progress bar stop increasing once the button below is pressed? I tried a couple of different things. I would love to be able to use jQuery to make it work or angularJS but vanilla JS would be great too!
I checked some of the code online as well but it wasn't working properly. I just want the progress bar to stop increasing during the loop. I should probably use clearInterval or setInterval.
Thanks!
(function move(){
var elem=document.getElementById("myBar");
var width=1;
var id=setInterval(frame,10);
function frame(){
if(width>=100){ // determine state
clearInterval(id);
} else{
width++; // loop increment
elem.style.width=width+"%";
elem.innerHTML=width*1+"millisecs";
}
}
function stop(){
//need code here to stop the bar from increasing..
}
})();
//jQuery.noConflict
window.onload = ()=>{
var trt = $(".aaanndd");
trt($("h1").toggle(4000));
};
progress::-moz-progress-bar {
color: #3fb6b2;
background: #efefef;
}
#myProgress {
font-style:arial;
border-color:white;
width: 100%
background-color: blue;
}
#myBar {
width: 1%;
height: 30px;
background-color: blue;
}
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<body>
<div class="section" position:absolute>
<div id="myProgress" position:absolute>
<div id="myBar"></div>
<h1> Timelimit Indicator</h1>
<br />
<button onclick="stop()">Stop Timer </button>
</body>
</html>