Javascript - Simple Loading Bar
Submitted by razormist on Saturday, April 28, 2018 - 20:47.
In this tutorial we will create a Simple Loading Bar using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is a text-based programming language meant to run as part of a web-based application. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding.
Next, we will create the home page after the load is finished Create another text file then write these block of codes inside the newly created text file then called it home.html.
There you have it we successfully created a Simple Loading 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!!
Before we started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the bootstrap that has been used for the layout https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. This code will render application and display the form that has a loading bar. To create this just write these block of code inside the text editor and save this as 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>
- #loadingholder{
- width: 100%;
- background-color:#ddd;
- }
- #loading{
- width: 0%;
- height:30px;
- background-color:#337AB7;
- }
- </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-8">
- <div id="loadingholder">
- </div>
- </div>
- </div>
- </body>
- <script type="text/javascript">
- Progress();
- </script>
- </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. To do this just create a new directory called js then copy and write these block of codes as shown below inside the text editor and save it as script.js in the newly created directory.- function Progress(){
- var loading = document.getElementById('loading');
- var width = 0;
- var interval = setInterval(Duration, 60);
- function Duration(){
- if(width >= 100){
- clearInterval(interval);
- window.location = 'home.html';
- }else{
- width++;
- loading.style.width = width + '%';
- }
- }
- }
Add new comment
- 286 views