• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

HTML Progress Bar Using JavaScript Source Code

rolec

Hardcore Survivalist
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
65
Likes
23
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
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
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/style.css"

    /

    >
  7. </

    head

    >
  8. <body

    >
  9. <nav class

    =

    "navbar navbar-default"

    >
  10. <div

    class

    =

    "container-fluid"

    >
  11. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  12. </

    div

    >
  13. </

    nav>
  14. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  15. <div

    class

    =

    "col-md-6 well"

    >
  16. <h3

    class

    =

    "text-primary"

    >

    HTML Progress Bar Using JavaScript Source Code</

    h3

    >
  17. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  18. <div

    class

    =

    "col-md-6"

    >
  19. <button

    class

    =

    "btn btn-primary"

    onclick

    =

    "startButton(this);"

    >

    PRESS ME!</

    button

    >
  20. <br

    /

    ><br

    /

    >
  21. <div

    id

    =

    "result"

    style

    =

    "display:none;"

    >
  22. <div

    id

    =

    "progressholder"

    >
  23. <div

    id

    =

    "progress"

    ></

    div

    >
  24. </

    div

    >
  25. <center

    ><h4

    >

    Please Wait.....</

    h4

    ></

    center

    >
  26. </

    div

    >
  27. </

    div

    >



  28. </

    div

    >
  29. </

    body

    >
  30. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  31. </

    html

    >

home.html
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    HTML Progress Bar Using JavaScript Source Code</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <div

    class

    =

    "col-md-2"

    ></

    div

    >

  18. <div

    class

    =

    "col-md-8"

    >
  19. <center

    ><h2

    >

    Please visit here <a

    href

    =

    "https://sourcecodester.com"

    >

    link</

    h2

    ></

    center

    >
  20. </

    div

    >



  21. </

    div

    >
  22. </

    body

    >
  23. </

    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
  1. function

    startButton(

    btn)

    {
  2. document.getElementById

    (

    'result'

    )

    .style

    .display

    =

    "inline"

    ;
  3. aniProgress(

    )

    ;
  4. btn.style

    .display

    =

    "none"

    ;
  5. }

  6. function

    aniProgress(

    )

    {
  7. var

    progress =

    document.getElementById

    (

    'progress'

    )

    ;
  8. var

    width =

    0

    ;
  9. var

    interval =

    setInterval(

    duration,

    60

    )

    ;


  10. function

    duration(

    )

    {
  11. if

    (

    width >=

    100

    )

    {
  12. clearInterval(

    interval)

    ;
  13. window.location

    =

    'home.html'

    ;
  14. }

    else

    {
  15. width++;
  16. progress.style

    .width

    =

    width +

    '%'

    ;
  17. }
  18. }

  19. }

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.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,512

356,407

356,429

Top
Raidforums