HTML Progress Bar Using JavaScript Source Code
Submitted by razormist on Saturday, February 15, 2020 - 15:24.
In this tutorial we will create a HTML Progress Bar using JavaScript. This code will dynamically display an animated progress bar when the user click the button. The code use onclick() function to call a specific method that will animate the progress bar by incrementing the width properties of an element and will stop if it reach the maximum width with 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 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"/>
- <link rel="stylesheet" type="text/css" href="css/style.css"/>
- </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"/>
- </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-8">
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will start an animated 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 startButton(btn){
- document.getElementById('result').style.display="inline";
- aniProgress();
- btn.style.display="none";
- }
- function aniProgress(){
- var progress = document.getElementById('progress');
- var width = 0;
- var interval = setInterval(duration, 60);
- function duration(){
- if(width >= 100){
- clearInterval(interval);
- window.location = 'home.html';
- }else{
- width++;
- progress.style.width = width + '%';
- }
- }
- }
Add new comment
- 253 views