Home  >  Article  >  Web Front-end  >  Example of JavaScript progress bar control implementation

Example of JavaScript progress bar control implementation

黄舟
黄舟Original
2017-11-21 11:20:351243browse

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:

Introduction to several methods of implementing progress bars in JavaScript


JavaScript native code to implement progress bar


## JS native upload large file display progress bar-php upload file

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn