SoFunction
Updated on 2025-04-10

JS achieves simple progress bar effect

This article has shared the specific code for implementing a simple progress bar for your reference. The specific content is as follows

Implementing the progress bar requires three parts:

1. Large external container
2. In the growth progress bar
3. Display the percentage of progress bar visualization

Use js to control the width of the progress bar to achieve this;

The specific code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
 <style>
 div{
 width: 500px;
 height: 50px;
 position: relative;
 border: 2px solid;
 margin: 0 auto;
 }
 aside{
 height: 50px;
 background:red;
 }
 p{
 position: absolute;
 top: 0;
 right: 0;
 }
 </style>
 <script type="text/javascript">
 var i = 0;
 var timer = setInterval(function(){
 ("aside"). = i++ + 'px';
 ("span").innerHTML = parseInt(i*100/500);
 if(i > 500){
 clearInterval(timer);}
 },10)
 </script>
</head>
<body>
 <div>
 <aside  style="width: 10px;"></aside>
 <p><span >0</span>%</p>
 </div>
</body>
</html>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.