Home > Web Front-end > JS Tutorial > body text

Example of JavaScript progress bar control implementation

黄舟
Release: 2017-11-21 11:20:35
Original
1302 people have browsed it

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>
Copy after login

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 ;
				 
			}
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template