Connecting Tech Pros Worldwide Help | Site Map

Extremely Simple Progress Bar

Death Slaught's Avatar
Site Addict
 
Join Date: Aug 2007
Location: Tennessee
Posts: 952
#1   Nov 23 '07
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



gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,128
#2   Nov 27 '07

re: Extremely Simple Progress Bar


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
Death Slaught's Avatar
Site Addict
 
Join Date: Aug 2007
Location: Tennessee
Posts: 952
#3   Nov 27 '07

re: Extremely Simple Progress Bar


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
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4   Nov 30 '07

re: Extremely Simple Progress Bar


Quote:

Originally Posted by Death Slaught

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.
Death Slaught's Avatar
Site Addict
 
Join Date: Aug 2007
Location: Tennessee
Posts: 952
#5   Dec 1 '07

re: Extremely Simple Progress Bar


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
Newbie
 
Join Date: Sep 2008
Posts: 4
#6   Sep 27 '08

re: Extremely Simple Progress Bar


Quote:

Originally Posted by gits

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
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,128
#7   Sep 29 '08

re: Extremely Simple Progress Bar


Quote:

Originally Posted by hannie

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
Reply


Similar JavaScript / Ajax / DHTML bytes