JavaScript - Simple HTML Progress Bar
Submitted by razormist on Sunday, July 7, 2019 - 19:49.
In this tutorial we will create a Simple HTML Progress Bar using JavaScript. This code will automatically display an animated progress bar when the user click the launch button. The code use onclick() to launch the animated progress bar by incrementing the width properties of an element again and again until it reach the maximum width by using setInterval(). This is a user-friendly program feel free to modify it.
We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.
home.html
There you have it we successfully created a Simple HTML Progress Bar using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/. And this is the link for the jquery that i used in this tutorial https://jquery.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as shown below. index.html- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <style>
- #progressholder{
- width: 100%;
- background-color:#ddd;
- }
- #progress{
- width: 0%;
- height:30px;
- background-color:green;
- }
- </style>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-6">
- <div id="result" style="display:none;">
- <div id="progressholder">
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <style>
- #progressholder{
- width: 100%;
- background-color:#ddd;
- }
- #progress{
- width: 0%;
- height:30px;
- background-color:green;
- }
- </style>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-6">
- <div id="result" style="display:none;">
- <div id="progressholder">
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will launch a progress bar when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory- function progressBar(){
- var progress = document.getElementById('progress');
- var width = 0;
- var interval = setInterval(progressDuration, 60);
- function progressDuration(){
- if(width >= 100){
- clearInterval(interval);
- window.location = 'home.html';
- }else{
- width++;
- progress.style.width = width + '%';
- }
- }
- }
- function launchProgress(){
- document.getElementById('result').style.display="inline";
- progressBar();
- }
Add new comment
- 192 views