473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,386 developers and data experts.

Extremely Simple Progress Bar

Death Slaught
1,137 1GB
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.   function progress() {
  5.    if (document.images["bar"].width < 400) {
  6.     document.images["bar"].width += 5;
  7.     document.images["bar"].height = 5;
  8.    } else {
  9.     clearInterval(ID);
  10.    }
  11.   }
  12.  
  13. var ID;
  14. window.onload = function() {
  15.   ID = setInterval("progress();", 500);
  16. }
  17. </script>
  18. </head>
  19. <body>
  20. <img src="black.gif" name="bar" />
  21. </body>
  22. </html>
black.gif is an extremely small square I made in paint.

- Death
Nov 23 '07 #1
16 42899
gits
5,390 Expert Mod 4TB
hi ...

good work very simple ... yes :) ... have a look at the following example that uses no image at all ... simply div/css, may be that could be used as an alternative pure dhtml-solution:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.         var prg_width = 200;
  5.  
  6.         function progress() {
  7.             var node = document.getElementById('progress');
  8.             var w    = node.style.width.match(/\d+/);
  9.  
  10.             if (w == prg_width) {
  11.                 w = 0;
  12.             }
  13.  
  14.             node.style.width = parseInt(w) + 5 + 'px';
  15.         }
  16.  
  17.         </script>
  18.     </head>
  19.  
  20.     <body onload="var progress_run_id = setInterval(progress, 250);">
  21.  
  22.         <div style="border: 1px solid black; width:200px; height:5px;">
  23.             <div id="progress" style="height:5px; width:0px; background-color:red;"/>
  24.         </div>
  25.  
  26.     </body>
  27. </html>
  28.  
kind regards
Nov 27 '07 #2
Death Slaught
1,137 1GB
Nice I never thought of doing it like that, I was going to add on to it making it more complecated when I got time.

Thanks, Death
Nov 27 '07 #3
acoder
16,027 Expert Mod 8TB
Nice I never thought of doing it like that, I was going to add on to it making it more complecated when I got time.
You could show the current percentage complete as the next step.

If this could be linked to some activity rather than just progress at regular intervals, it might have more use rather than just replace an animated loading indicator image.
Nov 30 '07 #4
Death Slaught
1,137 1GB
Yeah I planned on doing just that. The problem is, my free time is at an all time low. I have an extra credit site i'm working on, a site for a friends club, and high school to deal with :). So the second I get some free time, hopefully i'll have some in my first period, biology=boredom.

- Death
Dec 1 '07 #5
hannie
4
hi ...

good work very simple ... yes :) ... have a look at the following example that uses no image at all ... simply div/css, may be that could be used as an alternative pure dhtml-solution:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.         var prg_width = 200;
  5.  
  6.         function progress() {
  7.             var node = document.getElementById('progress');
  8.             var w    = node.style.width.match(/\d+/);
  9.  
  10.             if (w == prg_width) {
  11.                 w = 0;
  12.             }
  13.  
  14.             node.style.width = parseInt(w) + 5 + 'px';
  15.         }
  16.  
  17.         </script>
  18.     </head>
  19.  
  20.     <body onload="var progress_run_id = setInterval(progress, 250);">
  21.  
  22.         <div style="border: 1px solid black; width:200px; height:5px;">
  23.             <div id="progress" style="height:5px; width:0px; background-color:red;"/>
  24.         </div>
  25.  
  26.     </body>
  27. </html>
  28.  
kind regards
Really simple and useful progress bar.
BTW, how to detect the software image in jar or zip on completing download/upload so the progress bar disappears after loading.
Thanks.

Hannie
Sep 27 '08 #6
gits
5,390 Expert Mod 4TB
Really simple and useful progress bar.
BTW, how to detect the software image in jar or zip on completing download/upload so the progress bar disappears after loading.
Thanks.

Hannie
could you please explain in more detail what you want to do? typically you should wrap the shown code in a function and call it to start the progress-bar when you start a XMLHttpRequest. When the request is ready you just have to clear the interval and/or hide the progress-bar and display the received result in the request-object's final callback ...

kind regards
Sep 29 '08 #7
hi gits,

I stumbled upon this website while googling for an answer and I liked your solution. I have a question though: is it possible to have text (in the center) on top of the percentage bar? I managed to get it as a part of the div (id="progress") element but it only centers within "progress"'s width. I want it to be in the center of the parent div (which has a width of 200px).
Dec 15 '11 #8
gits
5,390 Expert Mod 4TB
do you mean something like this?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.         var prg_width = 200;
  5.  
  6.         function progress() {
  7.             var node  = document.getElementById('progress');
  8.             var tnode = document.getElementById('progressText');
  9.             var w     = node.style.width.match(/\d+/);
  10.  
  11.             if (w == prg_width) {
  12.                 w = 0;
  13.             }
  14.  
  15.             var val = parseInt(w) + 5;
  16.  
  17.             node.style.width = val + 'px';
  18.  
  19.             tnode.innerHTML = (val/prg_width * 100).toFixed(0) + ' %';
  20.         }
  21.  
  22.         </script>
  23.     </head>
  24.  
  25.     <body onload="var progress_run_id = setInterval(progress, 250);">
  26.  
  27.     <div style="width: 200px;">
  28.         <div id="progressText" style="text-align: center;">&nbsp;</div>
  29.         <div style="border: 1px solid black; height:5px;">
  30.             <div id="progress" style="height:5px; width:0px; background-color:red;"/>
  31.         </div>
  32.     </div>
  33.  
  34.     </body>
  35. </html>
  36.  
Jan 3 '12 #9
That's a nice one but maybe you could show an online demo on the site for dummies like me.
Jul 3 '12 #10
gits
5,390 Expert Mod 4TB
really? this is an example - you would just need to create a file, copy the code into it and open it in your browser. it cant be much more simple to see it in action - and its more to show how easy it is to create such 'widgets' with just a few lines of code, in case someone wants to build his own progressbar.
Jul 16 '12 #11
hi gits,

I am interested in your code, I used in my little project but i want to "attach" the progress bar to my javascript application. Also I want to know how to stop it x) .

Thanks
Aug 20 '12 #12
gits
5,390 Expert Mod 4TB
as you see it uses a setInterval in the page's onload event. you simply need to find the place in your code where you start an interval like this:

Expand|Select|Wrap|Line Numbers
  1. var progressIntv = setInterval(progress, 250);
and when you want to stop it, just call:

Expand|Select|Wrap|Line Numbers
  1. clearInterval(progressIntv);
as you see the variable progressIntv contains a reference to the interval.

as for the way to include it in your application it would be just guesswork to advice the best way. it depends on your app, because there are different ways and you might use the one that suits your app best.
Aug 21 '12 #13
Hi,

thanks for your quick reply. I finally stopped the progressbar. Actually I know how to attach it to my app, but I´m not sure if it is the best way.

Expand|Select|Wrap|Line Numbers
  1. var koniec = prompt("Enter a number:")
  2.  
  3. <body onload="var progress_run_id = setInterval(progress, koniec);">
  4.  
So.

Thanks.
Aug 21 '12 #14
gits
5,390 Expert Mod 4TB
ummm - what should the posted code show? basicly you influence the progressbar's progress-rate with the second parameter in the setInterval-method, that you obviously want to have set by a user-input? anyway - if it works for you as your app is intended to work then it could be ok :)
Aug 21 '12 #15
it does work but i have to divide the userinputnumber by 2 :/
Aug 22 '12 #16
gits
5,390 Expert Mod 4TB
huh? the parameter you set with the shown code does nothing more then to determine the intervall-poll - so seen from the point of the progress-bar it only determines how 'smooth' the bar is running.
Sep 19 '12 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Rob | last post by:
Hi all, Is it possible to do a progress bar of gauge bar in asp? If possible could someone show some sample code on it. Many thanks, Rob
1
by: Mike Lundell | last post by:
what's wrong with this, and .. can you not declare "char" variables? #include <iostream> int main() { int a = "* * * * * * * *\n"; std::cout << a; return EXIT_SUCCESS; }
10
by: Mike Lundell | last post by:
what's wrong with this, and .. can you not declare "char" variables? #include <iostream> int main() { int a = "* * * * * * * *\n"; std::cout << a; return EXIT_SUCCESS; }
3
by: rusttree | last post by:
Many moons ago, I took a class in embedded control at school. The course focused on a micro-controller mounted on a small electric car that was programmed using simple C code. The...
6
by: | last post by:
Why is my progress bar displayed only after it's reached 100%? <html> <style type="text/css"> #bar{ width: 10px; height: 14px; color: white; font-size: 12px; overflow: hidden;
1
by: mbatestblrock | last post by:
hello flash gurus, I am trying to get a very simple task done and for the life of me I cannot get it! www.shawnamariephotography.com If you go there I am sure you will see my problem. I took...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
1
by: James | last post by:
I've struggled for far too long on this, hoping someone can point me in the right direction. Created a new C# WebForm application in VS 2008. Added a "Report". Now all I want to do is have a...
1
by: darrel | last post by:
I have a web form where people can/will be attaching rather large files via a file upload field. I'd like to provide a progress bar and the easiest way to accomplish that seems to be to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.