rolec
Hardcore Survivalist
LEVEL 1
200 XP
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.
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
home.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
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!
Download
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.
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"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
HTML Progress Bar Using JavaScript Source Code</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-6"
>
- <button
class
=
"btn btn-primary"
onclick
=
"startButton(this);"
>
PRESS ME!</
button
>
- <br
/
><br
/
>
- <div
id
=
"result"
style
=
"display:none;"
>
- <div
id
=
"progressholder"
>
- <div
id
=
"progress"
></
div
>
- </
div
>
- <center
><h4
>
Please Wait.....</
h4
></
center
>
- </
div
>
- </
div
>
- </
div
>
- </
body
>
- <script
src
=
"js/script.js"
></
script
>
- </
html
>
home.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"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
HTML Progress Bar Using JavaScript Source Code</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-2"
></
div
>
- <div
class
=
"col-md-8"
>
- <center
><h2
>
Please visit here <a
href
=
"https://sourcecodester.com"
>
link</
h2
></
center
>
- </
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 +
'%'
;
- }
- }
- }
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!
Download
You must upgrade your account or reply in the thread to view the hidden content.