Home >Web Front-end >JS Tutorial >Example of JavaScript progress bar control implementation
In our previous article, we introduced to you several ways to implement progress bar in JavaScript, as well as cases of JavaScript native implementation of progress bar, so today we will continue to give you Introducing an example of JavaScript progress bar control implementation!
First define a p with a span embedded in it:
<p id="loadbar"> <span id="bar" style="width: 10%;">10%</span> </p>
Then use css to complete the style of the progress bar:
p#loadbar{ width:300px; background-color: silver; border:1px solid salmon; text-align: center; border-radius:8px ; } #bar{ display: block; font-family: arial; font-size: 12px; background-color: sandybrown; text-align: center; padding: 5px; border-radius:5px ; }
Finally, use js to control the progress bar display:
var i=0; function startbar(){ var showbar=setInterval("setbar()",1000); } function setbar(){ console.log("setbar"); i+=5; if(i>=100) { clearInterval(showbar); } document.getElementById("bar").style.width=i+"%"; document.getElementById("bar").innerHTML=i+"%"; } startbar();
The effect is as follows:
Summary:
After studying this article, do you believe that you are familiar with the implementation of JavaScript progress bar control? I have gained a certain understanding and hope it will be helpful to your work!
Related recommendations:
The above is the detailed content of Example of JavaScript progress bar control implementation. For more information, please follow other related articles on the PHP Chinese website!